NextJS and PersistQueryClientProvider #4443
-
Hello everyone :) Here's my use-case: I need some of my queries to be persisted using sync storage persister (authentication data), all other queries doesn't have to be persisted. I figured I can use multiple providers to achieve it, however when I use only one provider - PersistQueryClientProvider I get error. In function MyApp({ Component, pageProps }: Props) {
return (
<PersistQueryClientProvider client={persistQueryClient} persistOptions={{ persister }} context={persistContext}>
<Hydrate state={pageProps.dehydratedState}>
<ReactQueryDevtools initialIsOpen={false} />
<Component {...pageProps} />
</Hydrate>
</PersistQueryClientProvider>
);
} but I'm getting versions
What am I doing wrong? Thank you in advance |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The easiest way to do this is to "tag" your queries that you want to persist, either via the
and then filter them down via
|
Beta Was this translation helpful? Give feedback.
PersistQueryClientProvider
internally creates aQueryClientProvider
and forwards the props to it. So when you create one withcontext={persistContext}
, all consumers would need to use the custom context as well. This is certainly not what you want - custom context is not meant for this scenario I believe.The easiest way to do this is to "tag" your queries that you want to persist, either via the
queryKey
or via themeta
field: