feat: auto-resolve QueryClient in hooks from <QueryClientProvider />#345
Merged
Conversation
QueryClient in hooks from <QueryClientProvider />
…eryClient from the `<QueryClientProvider />` context instead of requiring it to be passed in explicitly when the API Client created.
…Client from the `<QueryClientProvider />` context instead of requiring it to be passed in explicitly when the API Client created.
c22f1ca to
8f0b86a
Compare
🦋 Changeset detectedLatest commit: 8f0b86a The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This update simplifies the usage of our React hooks by pulling the
QueryClientdirectly from the<QueryClientProvider />context. Now, hooks like useQuery, useMutation, and useFetching no longer require an explicitly passed client when initializing the API client - making them more ergonomic and reducing boilerplate.What’s changed
Hooks (
useQuery,useMutation,useFetching, etc.) will automatically grab the QueryClient from context.You can omit the queryClient option when creating your API client if you only need it for hook-based operations.
Note: Low-level methods on the API client - such as
setQueryData,getQueryData, etc. - still require you to supply aQueryClientwhen the client is instantiated.Why
Improves developer experience by removing repetitive passing of the same
QueryClient.Aligns with TanStack React Query’s recommended pattern of using a provider for client injection.