-
Read the docs and rewatched videos a few times but still cannot make it work. I have two NextJS pages, one has useQuery and another is static. When I browse these pages:
At the step 3 I expect that the data is loaded from cache (and then does background refetch as staleTime=0) but instead I see hard load as at the step 1. queryKey doesn't change, default options, version 3.15.0. What do I do wrong? Or is it expected behaviour? Should I manually load data from cache in this case? Update: I have created a Sandbox and it works as expected. What could be the reason of failed cache in my case? Could other Providers affect QueryClientProvider? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
If it works in a sandbox, the two most prominent gotchas would be:
|
Beta Was this translation helpful? Give feedback.
-
I found the problem! I was calling When I moved that code to the top level I saw cache working properly: // pages/_app.js
import { QueryClient, QueryClientProvider } from "react-query";
import { ReactQueryDevtools } from "react-query/devtools";
const queryClient = new QueryClient();
export default function MyApp({ Component, pageProps }) {
return (
<QueryClientProvider client={queryClient}>
<Component {...pageProps} />
<ReactQueryDevtools initialIsOpen={false} />
</QueryClientProvider>
);
} I have updated the Sandbox example which could be used to start experimenting with NextJS + ReactQuery. |
Beta Was this translation helpful? Give feedback.
-
Thanks @ignat . It helped me a lot |
Beta Was this translation helpful? Give feedback.
I found the problem!
I was calling
new QueryClient()
inside MyApp function. So with any new page I got new query client.When I moved that code to the top level I saw cache working properly:
I have updated the Sandbox example which could be used to start experimenting with NextJS…