DocsBlog

Get Started

Components

Data Grid

Signals

Styling

Theming

↑↓Navigate
↵Select
EscClose
  • 1.8.0

  • Day

    Night

    Preview

    Switch mode
  • cerberus

    acheron

    elysium

    oceanus

Get Started
Components
Data Grid
Signals
Styling
Theming

Get started

OverviewReactivityData FetchingGlobal Stores

Primitives

Creating SignalsCreating QueriesCreating MutationsComputing Signal ValuesCreating EffectsContextual Signal StoresBatch UpdatesCleanup EffectsUntrack Signals

Hooks

Using QueriesUsing MutationsReading Primitive SignalsUsing SignalsUsing Store Instances

Components

Reactive Text

Using Mutations

Learn how to use defined mutations in React.

  • source
View as Markdown
Open this page in Markdown
Anthropic
Open in Claude
Ask questions about this page
OpenAI
Open in ChatGPT
Ask questions about this page
import { useMutation } from '@cerberus/signals'

Usage

useMutation allows you to use a mutation factory (via createMutation) within the scope of a React component.

Mutations's allow you to update the state of a query and have built in support for Suspense and Error Boundaries with no extra effort.

When utilizing the invalidate option, a query will automagically update once the mutation has resolved. Combing this with onMutate/setQueryData will create optimistic updates in the UI.

Using Mutations

To use a mutation call the mutate method from the return Object.

Loading example...

Data

The data property contains the returned value of the mutation. This is not necessary for UI updates as mutations were designed to update querys on your behalf through invalidation.

Loading example...

Status

The status property is the lifecycle state associated with the mutation. To learn more about mutation lifecycles, see the create mutation docs.

Loading example...

API

useMutation accepts the following options:

ParamsRequiredDescription
MutationTupleYesThe value of the defined mutation factory.

Return

useMutation returns and Object with the following options:

PropertyTypeDescription
mutate(variables: V) => Promise<T>A function that calls the defined mutation Promise.
statusMutationStatusThe Promise-based status state of the mutation.
dataT | undefinedThe cached state of the query associated with it.
errorunknown | undefinedThe error thrown from the mutation.

On this page

  • Usage
  • Using Mutations
  • Data
  • Status
  • API
    • Return
Edit this page on Github

User 39628670-af6c-4bfb-aa68-6ef2a2a9f9a8

idle
{
  "id": "496fc170-cff1-4481-830b-e11ff04f687c",
  "name": "Cerby the Dawg"
}
Cerby Mutation Data:
Add Mutation Data:

User 6670ca30-9e32-4549-a04c-131ee2084b40

idle