Skip to content

Function: useMutation()

useMutation<M, K>(name): UseMutationResult<M, K>

Defined in: react/src/use-mutation.ts:43

Convenience wrapper around client.mutate(name, args) with pending / error state suitable for buttons and forms.

const create = useMutation<typeof mutators, "createTodo">("createTodo")
...
<button disabled={create.isPending} onClick={() => create.mutate({ title })}>Add</button>

The mutation returns after the local optimistic apply, so the calling component can dismiss dialogs / clear inputs immediately; the push and subsequent pull happen in the background.

M

K extends string

K

UseMutationResult<M, K>