--- id: useMutation title: useMutation --- ```ts function useMutation(options, queryClient?): UseMutationReturnType; ``` Defined in: [packages/vue-query/src/useMutation.ts:231](https://github.com/TanStack/query/blob/main/packages/vue-query/src/useMutation.ts#L231) Unlike queries, mutations are typically used to create/update/delete data or perform server side-effects. `useMutation` is the composable for that. `options` may be a plain object, a `ref`, or a reactive getter (`() => ({ ... })`) — pass a getter if the options themselves depend on other reactive state. ## Type Parameters ### TData `TData` = `unknown` ### TError `TError` = `Error` ### TVariables `TVariables` = `void` ### TOnMutateResult `TOnMutateResult` = `unknown` ## Parameters ### options [`UseMutationOptions`](../type-aliases/UseMutationOptions.md)\<`TData`, `TError`, `TVariables`, `TOnMutateResult`\> The [UseMutationOptions](../type-aliases/UseMutationOptions.md) to use — everything you can pass to `useMutation`. ### queryClient? [`QueryClient`](../classes/QueryClient.md) Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin` will be used. ## Returns [`UseMutationReturnType`](../type-aliases/UseMutationReturnType.md)\<`TData`, `TError`, `TVariables`, `TOnMutateResult`\> `mutate`/`mutateAsync` also accept per-call `onSuccess`/`onError`/`onSettled` callbacks as a second argument, useful for triggering call-site side effects (e.g. navigation) without coupling them to the shared mutation definition. Hook-level callbacks (passed to `options`) fire for every mutation; per-call callbacks fire only for the latest call you've made. ## See [mutationOptions](mutationOptions.md) to share these options across multiple `useMutation` call sites, or to look the mutation up elsewhere via its `mutationKey` (e.g. with `useMutationState`). ## Examples ```vue ``` Rendering the mutation's own state, rather than just firing it off: ```vue ``` Optimistic update via `onMutate`, rolling back on `onError`: ```vue ``` Callbacks passed per call to `mutate` only fire for the last call — `mutateAsync` gives you a promise per call instead, so you can wait for all of them when they succeed: ```vue ``` If some of the mutations above can fail independently of the others, and you want to know which ones did — rather than losing that information the moment the first one rejects — swap `Promise.all` for `Promise.allSettled`: ```vue ```