Next.js Discord

Discord Forum

Keep fetched data between pages

Answered
Sw1ndler posted this in #help-forum
Open in Discord
As seen here, when I navigate to a new page, there is a new request to get user data
Is there a way to use the previously fetched data?

https://lemonhost.pics/Sw1ndler/DQdXbm7ySm
Answered by New Guinea Freshwater Crocodile
idk then, im new and only know about app router. but if you're not using swr look into that cuz you will be able to cache these user info and invalidate it on logout or depending on some other criteria
View full answer

10 Replies

New Guinea Freshwater Crocodile
app or pages router?
pages
im considering using localstorage but I assume there is a better alternative
New Guinea Freshwater Crocodile
idk then, im new and only know about app router. but if you're not using swr look into that cuz you will be able to cache these user info and invalidate it on logout or depending on some other criteria
Answer
swr seems like a good idea, does it persisent between pages though?
New Guinea Freshwater Crocodile
yeah but i think you may need to disable some of the automatic revalidations
automatic revalidations seems like a good idea to me
New Guinea Freshwater Crocodile
oh i see
thanks for the help, ill check it out