NextJS - Maintain cache while navigating between different pages #7518
Unanswered
george-roussos
asked this question in
Q&A
Replies: 1 comment 8 replies
-
That's not true. You should have one |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, this is my first time using react-query on a NextJS project.
Using it in a single page React app has been no problems re: the shared cache. Like, you go in one page, navigate to another, go back to the first page, data is cached, served, done.
I am realising just now that with NextJS that is not really the case, since the docs advise on every page having its own
queryClient
instance. This is good and motivated in the docs, however, I was hoping to benefit from the cache while the user is navigating between different pages. Is there a way to do this? I am guessing with a shared, exportedqueryClient
instance this might be possible - but what are the caveats and what is the correct way to do so accounting for hydration (right now I have the hydration boundary wrapping everything in my_app.tsx
(usingpages/
structure). I don't believe my pages expose any sensitive data (I get my data from a contentful instance and no authentication or similar is involved).By the way, thanks for this tool, what a thing...
Beta Was this translation helpful? Give feedback.
All reactions