Replies: 2 comments 6 replies
-
If you want to refetch it regardless, you can do:
either one of those calls will refetch those right away. |
Beta Was this translation helpful? Give feedback.
-
Hi there @bennik88 , I am curious if you have found a solution. Currently, I'm having a similar problem with Next.js 14.0.4. I have 2 pages, let's call them I have the client provider set up same way as it's suggested in the docs. From what I was able to investigate, when you open a new tab/window in your browser, your provider runs again and a new query client is created. When I console logged the query client's cache in those respective pages, they only logged the queries that were run while landing to respective pages and proved that they were using different client instances. So I believe there is no solution to this since the instances are different. Maybe being able to create a query client in server side would help, I'm not sure at the moment. This discussion was closest I found so leaving this comment and hoping it might clear some questions for people visiting here further. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Question
How do I update or invalidate a Query from a different page without additional state management libraries like useContext or Jotai?
Problem
I'm having for example two pages. Home and Contacts both are their own components under different URLs.
Home has
getNewestContacts
which is getting the 5 newest contacts on load. I don't want them to update on Mount neighter need they be updated on window focus so I disable that. But I want them to update when changing thecontacts
mutation on the other page.Now I have the Contacts page with
getContactsCount
anddeleteContact
. Which are working great by themself. The only thing that is now working is invalidatingnewestContacts
. I tried usingqueryClient.invalidateQueries(["newestContacts"]);
. I think it would work if I use the context API and pass it to Home and then put it into the dependencies array but I guess this is totally missing the point of using TanStack Query. I've also tried to use"contacts"
as a dependency sting in["newestContacts", "contacts", currentUser],
which also didn't work. I coun't find an example for this in the docs.Package and OS versions:
OS: MacOS
"next": "^12.3.0",
"@tanstack/react-query": "^4.1.0",
Beta Was this translation helpful? Give feedback.
All reactions