Provider in Server Component?
hello, I'm a junior developer and I am a newbie with react-query. does it make sense to wrap the root component '/' in next.js, which is a server component with a QueryClientProvider?
If not, how would you decide where to wrap the application with the Provider? I assume it is good pattern to use only one provider per application?
sorry, I could not find clear answers to these questions.
3 Replies
rival-black•3y ago
maybe look up how react context works, it's an interesting read. Normally you would only wrap your application in a single provider so that it's data can be shared between all child components.
mere-teal•3y ago
here is how you'd do it in next13 with server components: https://tanstack.com/query/v4/docs/react/guides/ssr#queryclientprovider-is-required-by-both-the-initialdata-and-hydrate-prefetching-approaches
SSR | TanStack Query Docs
React Query supports two ways of prefetching data on the server and passing that to the queryClient.
Prefetch the data yourself and pass it in as initialData
rare-sapphireOP•3y ago
thank you again. I am slowly getting my head around the library:
https://github.com/umud85/tanstack-exercise
GitHub
GitHub - umud85/tanstack-exercise
Contribute to umud85/tanstack-exercise development by creating an account on GitHub.