query/mutation cache 'onSuccess', 'onError', etc handlers cannot access the queryClient. #3450
Unanswered
lm-chad-simmons
asked this question in
Ideas
Replies: 1 comment 2 replies
-
This seems to work fine:
TypeScript is also fine with it because config is a public property. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm building a simplified model CRUD framework using react query, and I have a need to configure a number of defaults for various queries and mutations. Specifically I'd like to have the mutationCache invalidate queries in the onSuccess handler (to update query results that are filtered based on data that has been mutated). Since the mutationCache and queryCache both need to be created (and configured with the onSuccess handler) before dropping them into the queryClient configuration I don't have access to the queryClient when I'm configuring the mutation cache.
I have thought of a couple of options for working around the issue:
The latter makes for a leaky abstraction, while the former just seems like a hack. The real fix for this would be to provide the queryClient to the onSuccess (and other) handlers so they can properly update the cache's as needed.
Beta Was this translation helpful? Give feedback.
All reactions