Skip to main content
Perform mutations and side effects with the createMutation primitive. It provides methods to trigger mutations and tracks their state reactively in SolidJS.

Signature

Parameters

Accessor<CreateMutationOptions<TData, TError, TVariables, TContext>>
required
A Solid accessor (function) returning mutation configuration options.
Accessor<QueryClient>
Accessor returning a custom QueryClient instance. If not provided, uses the client from context.

Returns

object
Reactive 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

Reset Mutation State

Multiple Mutations

Error Handling with Retry

Reactive Mutation Options

Mutation with Loading State

Notes

The options parameter must be an accessor (function) to integrate with SolidJS reactivity system.
Use mutate for fire-and-forget operations and mutateAsync when you need to await the result or handle errors with try/catch.
Always invalidate or update relevant queries after a successful mutation to keep your UI in sync with the server state.