query: ContextSharing not working for different modules
Describe the bug
When using the QueryClientProvider in an npm package and requiring the query client via useQueryClient in the consumer app, I am always getting the following error:
Error: No QueryClient set, use QueryClientProvider to set one
It seems like the logic for getting the shared context is broken.
Expected behavior
Using the useQueryClient should check for the shared ReactQueryClientContext and use it if existing.
Additional context
With #1912 the context sharing was disabled by default, and seems to have been disabled at all.
It seems like the QueryClientSharingContext is always false, as it is initialized with that value:
https://github.com/tannerlinsley/react-query/blob/05a8057e2be64915d2a12b716d8131f113598dbd/src/react/QueryClientProvider.tsx#L12
https://github.com/tannerlinsley/react-query/blob/05a8057e2be64915d2a12b716d8131f113598dbd/src/react/QueryClientProvider.tsx#L34
Shouldn’t the context be initialized with whether there is a shared context or a boolean value, passed to the useQueryClient hook?
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 25 (5 by maintainers)
yep this
you’d need to provide a reproducible example of some sorts please. also, in v4, there is the option to pass a custom query context for scoped providers. Have a look at the example in the migration guide: https://tanstack.com/query/v4/docs/guides/migrating-to-react-query-4#custom-contexts-for-multiple-providers