Skip to main content
Perform mutations and side effects with the useMutation composable. It provides methods to trigger mutations and tracks their state reactively.

Signature

Parameters

UseMutationOptions<TData, TError, TVariables, TContext>
required
Configuration options for the mutation. Can be a reactive ref or getter function.
QueryClient
Custom QueryClient instance. If not provided, uses the client from context.

Returns

object
Reactive refs containing mutation state and methods.

Type Parameters

  • TData - Type of data returned by the mutation
  • TError - Type of error (defaults to DefaultError)
  • TVariables - Type of variables passed to the mutation (defaults to void)
  • TContext - Type of context returned by onMutate (defaults to unknown)

Examples

Basic Usage

With TypeScript

Optimistic Updates

Using mutateAsync

Per-Mutation Callbacks

Reactive Mutation Options

Reset Mutation State