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
fair-rose•9mo ago
https://tanstack.com/query/v5/docs/framework/react/reference/useMutation
see the API reference
extended-salmonOP•9mo 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.
fair-rose•9mo ago
Can you explain what you are trying to do?
ugly-tan•9mo ago
Dominik has said he sees no reason to create
mutationOptions
. You could try to demonstrate your use case and see if he’ll reconsiderextended-salmonOP•9mo 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.
sensitive-blue•9mo 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.
magic-amber•9mo 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.