useMutationState
TheuseMutationState hook provides access to the state of one or more mutations. It can be used to track mutation status, data, errors, and more across your application.
Import
Signature
Type Parameters
type
default:"MutationState"
The type of data to return for each mutation. Defaults to full
MutationState.Parameters
object
Configuration options
MutationFilters
Filters to narrow down which mutations to include
MutationKey
Filter by mutation key
boolean
If true, only match mutations with the exact mutation key
MutationStatus
Filter by mutation status: ‘idle’, ‘pending’, ‘success’, or ‘error’
(mutation: Mutation) => boolean
Custom predicate function to filter mutations
(mutation: Mutation) => TResult
Transform function to select specific data from each mutation. Defaults to returning the full mutation state.
QueryClient
Optional QueryClient instance. If not provided, uses the context client.
Returns
Array<TResult>
An array of mutation results based on the select function. Defaults to an array of
MutationState objects.MutationState Type
Examples
Get All Mutation States
Filter by Mutation Key
Select Specific Data
Track Recent Errors
Show Success Messages
Upload Progress Tracker
Custom Predicate
Mutation History
Aggregate Mutation Data
Track Specific Mutation Instance
Notes
- The hook subscribes to the mutation cache and updates when mutations change
- Returns an array that can be empty if no mutations match the filters
- Uses
useSyncExternalStorefor efficient subscriptions - The
selectfunction is useful for extracting only the data you need - Mutations are kept in memory even after they complete, allowing you to track history
- Use filters to narrow down results and improve performance
- The hook uses deep equality checking to prevent unnecessary re-renders
- Each mutation has a unique
mutationIdthat can be used for keying