T
TanStack2y ago
correct-apricot

Purpose and necessity of QueryClient

Junior dev, newish to react-query & reading the docs - quick question. Among the first couple pages that I've read from the documentation (great documentation btw), there have been quick start examples of how to use it with some good explanations but I've come across the QueryClient on those occasions with little explanation. All I can remember from the API docs for the QueryClient is that it's used for caching. Yet the first couple examples have shown to use it along with the context provider but not much explanation or actual use of it. I'm sure I can get around to it but I'd really like to nail the fundamentals asap, so, can anyone clarify what the QueryClient is, its purpose and its necessity? Can you use useQuery without it?
1 Reply
deep-jade
deep-jade2y ago
no, you can't useQuery without it. The QueryClient holds the QueryCache, which is the store where your data is stored. We usually distribute the queryClient via react context, but you can also pass it as an argument to useQuery directly if necessary.

Did you find this page helpful?