Next.js Discord

Discord Forum

Refresh data on navigation

Answered
Dwarf Hotot posted this in #help-forum
Open in Discord
Dwarf HototOP
Hi,
I'm still new and experimenting and I don't know to achieve a simple thing.
A page gets its data using a prisma request.
On first load, the data loads properly.
When data changes, I'd like to get it refreshed, but I don't need realtime, just when navigating back to the page.
Who do I do this?
Answered by Ray
export const dynamic = 'force-dynamic'
View full answer

25 Replies

Dwarf HototOP
Should I use classic react hooks? like useEffect?
Dwarf HototOP
that's actually the question 🙂
maybe it wasn't clear
page is static by default
when you update the data in database, you will need to revalidate the cache or rebuild the page
with revalidatePath or revalidateTag
Dwarf HototOP
Data can be changed from outside of my application
do you want your page being static or dynamic
Dwarf HototOP
should I do a simple routing, with a timer or some kind of stuff to revalidate periodically ?
I guess I need it to be dynamic then
export const dynamic = 'force-dynamic'
Answer
Dwarf HototOP
love it
or export const revalidate = 15
this will revalidate the page on next visit when 15 sec is passed from previous visit
Dwarf HototOP
force-dynamic did the trick, thanks
revalidate seems to be a clever approach though
but I doesn't seems to work with my use case
@Dwarf Hotot but I doesn't seems to work with my use case
refresh the page again
Dwarf HototOP
refreshing seems to always work, even without export const revalidate = 15, but that's not quite a use case, nobody hits f5 while browsing right?
Dwarf HototOP
ok, but I'd like to have always fresh up-to-date data for everyone
@Dwarf Hotot ok, but I'd like to have always fresh up-to-date data for everyone
then just do export const dynamic = 'force-dynamic'
Dwarf HototOP
alright, thanks
@Dwarf Hotot alright, thanks
no prob