Next.js Discord

Discord Forum

Re-fetching data when component loads

Answered
Orchard Oriole posted this in #help-forum
Open in Discord
Avatar
Orchard OrioleOP
i have a navigation and 2 components. one of those components, UserInformation fetches user data and displays it. when i go to the other component and back, the data stays the same (even though its updated in the db)

how can i make sure it re-fetches the data every time? is it possible with a server component like this or does it have to be a client component?
Answered by Ray
I would suggest using react-query/swr
View full answer

10 Replies

Avatar
Orchard OrioleOP
Anyone?
Avatar
Ray
sound like router cache, does it show updated data when you refresh the page?
Avatar
Orchard OrioleOP
Yes
Avatar
Ray
try fetching the data client side if you want to prevent the data cache in router cache. because its impossible to disable router cache atm
Avatar
Orchard OrioleOP
How would I do that?
Avatar
Ray
I would suggest using react-query/swr
Answer
Avatar
Ray
btw, is seo important for that page?
Avatar
Orchard OrioleOP
Nope
I’ll look into it
Thanks