Skip to content

revalidating data on server clears tanstack queryClient #9124

Closed Answered by Korat-Dishant
Korat-Dishant asked this question in Q&A
Discussion options

You must be logged in to vote

Issue was with creating queryClient directly.

initializing QueryClient using state solved the issue.

  const [queryClient] = useState(() => new QueryClient( ));

When initializing QueryClient directly in layout or provide causes issues when revalidation actions are called. The reason being is that when the server side cache is cleared it cause layout re-render and hence QueryClient is re-initialized. Wrapping QueryClient in useState solves this problem.

special thanks to :
ISDuffy's comment
and
https://www.youtube.com/watch?v=b_UQ1bdQddw&t=419s
for providing solution

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Korat-Dishant
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant