React Query + NextJS Query Params
I have a React Query inside a React Hook which I am accessing from a NextJS route. Example: /about
When I access the route directly, the query works as expected and I can see the query in the react query dev tools. However, I am using NextJS URL query params to control some state. When I access the page with the query params, the react query doesn't work as expected - I cannot invalidate the state and the state doesn't even show in the react query dev tools. Example: /about?isquery=true
6 Replies
rare-sapphireOP•3y ago
Hopefully I described this properly 🤷🏻♂️
It seems that it is being treated as a separate page, however the same components are loaded. Only React Query data is missing
correct-apricot•3y ago
Would you be able to share some code to provide more context?
rare-sapphireOP•3y ago
Save this in pages as example.tsx - Go to http://localhost:3000/example with devtools open & you'll see example key + data. Go to http://localhost:3000/example?withquery=true and it's not there
correct-apricot•3y ago
Seems to work for me: https://stackblitz.com/edit/nextjs-by1mpn?file=pages/example.js
Nextjs (forked) - StackBlitz
The React framework for production.

rare-sapphireOP•3y ago
You're right, it does work there. That's strange.
correct-apricot•3y ago
I would look for differences in your setup vs the link I shared