Is it not possible to use useQuery in the root component of Nextjs app?
I am trying to use useQuery in the _app.js file of Nextjs framework (which is the root component of the app in Nextjs) and am constantly getting error
No QueryClient set, use QueryClientProvider to set one. However I have already set the QueryClientProvider and everything works well if I shift the use of useQuery to any other component other than root component. It seems like something is not ready yet before I set the QueryClientProvider. Can someone please help to understand that part?2 Replies
conscious-sapphire•4y ago
It's the same as using useParams outside the Provider from react-router, or using useSelector outside of the redux provider. It doesn't work. Because useQuery reads the queryClient from that context, it cannot be used outside of it.
genetic-orangeOP•4y ago
thank you TkDodo, I was just going through you 16 part material on react-query. Thank you for sharing that publicly for free