Skip to content

Can't get cache working or/and don't understand how it works #2228

Answered by ignat
ignat asked this question in Q&A
Discussion options

You must be logged in to vote

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:

// 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…

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@TkDodo
Comment options

@ignat
Comment options

@TkDodo
Comment options

Answer selected by ignat
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants