Skip to content

NextJS and PersistQueryClientProvider #4443

Answered by TkDodo
bartekczyz asked this question in General
Discussion options

You must be logged in to vote

PersistQueryClientProvider internally creates a QueryClientProvider and forwards the props to it. So when you create one with context={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.

I need some of my queries to be persisted using sync storage persister (authentication data), all other queries doesn't have to be persisted

The easiest way to do this is to "tag" your queries that you want to persist, either via the queryKey or via the meta field:

useQuery({ queryKey: [type: 'todos', { persist: true }], queryFn })

useQuery({ queryKey: [type: 'todos' ], queryFn, meta:…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@bartekczyz
Comment options

Answer selected by bartekczyz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants