queryFn Gets client, But Why Not mutationFn? #9512
Unanswered
raymondanythings
asked this question in
Ideas
Replies: 1 comment
-
we actually have a PR up for this: but it seems like you’d want it in the callbacks, not in the |
Beta Was this translation helpful? Give feedback.
0 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.
Uh oh!
There was an error while loading. Please reload this page.
-
Mutation
is commonly used to modify server state.As a result, it's often necessary to access the
queryClient
for tasks like optimistic updates.After noticing that client is passed as an argument to
queryFn
, I tried using it withmutationFn
as well, but found that this functionality is currently not supported.Problem
To update the query cache, we currently need to wrap the mutation in a custom hook, like this:
However, if the client could be passed as an argument like in
queryFn
, the intended behavior of the mutation could be implemented more easily:This would allow all necessary logic to remain within the mutation hook itself, without requiring a custom wrapper.
Why This Matters
With the addition of
mutationOptions
, it's now possible to structure mutations separately in their own layer.However, accessing the query cache via a custom hook feels contrary to that design intention.
If we could access
queryClient
directly withinmutationOptions
, it would align better with the purpose of mutations and eliminate the need for additional boilerplate.Beta Was this translation helpful? Give feedback.
All reactions