Next.js Discord

Discord Forum

Get refreshed data w/o using fetch

Unanswered
Pollock posted this in #help-forum
Open in Discord
PollockOP
Hi, I'm getting some dynamic data. I'm not using fetch so I'm wondering if I can still have it not used cached data.

11 Replies

So first of all, these data aren’t cached right? So your page isn’t cached and it’s should be dynamic rendered (if no, add export const revalidate = 0;)
If your page is dynamic rendered but still getting the previous data when navigating back, it’s caused by the router cache (aka client-side cache). For that, you have to revalidate it by calling router.refresh, currently you can’t opt out of router cache.
PollockOP
I'll try that. Ya I made my own button the user can click to go back, and I did use the router.refresh. But when I click the browser's back button, the data is old
I see, router.refresh only refresh the current page, so you probably have to add it in a useEffect in the page you want to revalidate
PollockOP
Hmm I don't think I want to make it a client component. Maybe I'm seeing why though I should use fetch
No, you can just create a client component and put it in the page
what only matters is your router.refresh, you can put it anywhere
@Pollock Hmm I don't think I want to make it a client component. Maybe I'm seeing why though I should use **fetch**
And fetch doesn’t change the router cache as it’s clear that it can’t be opt out. An alternative is client-side data fetching which is what you don’t wanted
PollockOP
is router cache different than what's being done here? I've seen in several tutorials now that show a 2nd argument for fetch where you can have it refresh
Yes, it’s server-side revalidate. Router cache is at client-side which lasts for 30 seconds
PollockOP
Thanks I'll look into that 🙂