Skip to content

Default mutation function, POST, PATCH, etc #8192

Answered by TkDodo
ysageev asked this question in Q&A
Discussion options

You must be logged in to vote

Is there a place to define a defaultMutationFn?

You can add a mutationFn to defaultOptions of mutations in the QueryClient, just like you can with queries:

new QueryClient({
  defaultOptions: {
    mutations: {
      mutationFn: () => ...
    }
  }
})

How, in that mutationFn, do you distinguish between a PUT, PATCH, DELETE or POST?

That’s up to you. You can pass it in as part of the variables, or you can set meta to contain that.

Is it possible to have a defaultInsertFn and defaultUpdateFn etc.?

No because react-query isn’t tied to http

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ysageev
Comment options

Answer selected by ysageev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants