Wrapping QueryClientProvider
Hello,
Is wrapping
QueryClientProvider a bad practice ? I'm interested in doing this in order to be able to use React Router's useNavigate hook within both queryCache & mutationCache onError handlers in order to redirect globally on 401 errors and I can't do this if the QueryClient is defined outside of React...
Cheers6 Replies
other-emerald•3y ago
I don't see any issue with it, as long as no hooks (
useQuery, useQueryClient etc..) are called outside of the boundaries of the QueryClientProvider.sunny-greenOP•3y ago
Hmm maybe not ... getting an infinite loop 🤬
mute-gold•3y ago
Wrapping the provider component, no. Defining the query client inside of a component, possibly. You'd need to use a state value or ref to prevent the client from being instantiated repeatedly every time the component renders, as you would when using Next.js
sunny-greenOP•3y ago
Yup that's what I thought but I'm still getting the loop despite trying both approaches.
other-emerald•3y ago
If you could share a minimal example or a sandbox, that would probably help us understand more!
sunny-greenOP•3y ago
Yes indeed, will do as soon as I get a chance!