queryOptions counterpart for useMutation?
Hello everyone,
I recently discovered that you can share configurations between queries using
queryOptions as mentioned in this section of the documentation:
https://tanstack.com/query/v5/docs/framework/react/guides/query-options
I was wondering if there was a counterpart for this for useMutation.Query Options | TanStack Query React Docs
One of the best ways to share queryKey and queryFn between multiple places, yet keep them co-located to one another, is to use the queryOptions helper. At runtime, this helper just returns whatever yo...
7 Replies
mute-gold•12mo ago
https://tanstack.com/query/v5/docs/framework/react/reference/useMutation
see the API reference
absent-sapphireOP•12mo ago
What I’m trying to do is something similar to this example but with mutations:
It’s only a helper function that contains typing but I don’t seem to find the equivalent in mutations.
mute-gold•12mo ago
Can you explain what you are trying to do?
generous-apricot•12mo ago
Dominik has said he sees no reason to create
mutationOptions. You could try to demonstrate your use case and see if he’ll reconsiderabsent-sapphireOP•12mo ago
I am trying to create a utility function that I can use between mutations where I only need to specify the id. Something like this would be Ideal:
If this were to be possible one could group success and error callbacks instead of having to rewrite that logic everywhere.
continuing-cyan•12mo ago
I'd check out this article:
https://tkdodo.eu/blog/mastering-mutations-in-react-query
But you can create a reusable function to do what I think you are looking for?
Mastering Mutations in React Query
Learn all about the concept of performing side effects on the server with React Query.
like-gold•12mo ago
For mutations, creating a custom hook is a good abstraction because you don't need to share the options with different methods like with queries.