T
TanStack4y ago
plain-purple

Is it best practice to use different QueryClients per user?

Assuming the anonymous user as a distinct user, is it wise to create a new QueryClient when the user switches from logged in to logged out or vice versa?
2 Replies
flat-fuchsia
flat-fuchsia4y ago
Not directly an answer… To isolate cached data per user on the same browser, we decided to make the userID a part of all our query keys. Thanks to queryKey factories we don’t have to think about adding it anymore. Regarding your question, I think it all depends on your query client configuration. If you have a lot of defaults in your queryClient for ex. It might be painful to re create it
gradual-turquoise
gradual-turquoise4y ago
you can also just clear the cache with queryClient.clear() when the user logs out. no need to really re-create it

Did you find this page helpful?