Skip to main content

useIsMutating

The useIsMutating hook returns the number of mutations that are currently pending (executing). This is useful for showing a global loading indicator for mutations.

Import

Signature

Parameters

MutationFilters
Optional filters to narrow down which mutations to count
MutationKey
Filter by mutation key
boolean
If true, only match mutations with the exact mutation key
(mutation: Mutation) => boolean
Custom predicate function to filter mutations
MutationStatus
Filter by mutation status: ‘idle’, ‘pending’, ‘success’, or ‘error’
QueryClient
Optional QueryClient instance. If not provided, uses the context client.

Returns

number
The number of pending mutations that match the filters

Examples

Global Mutation Indicator

In App Layout

Filter by Mutation Key

Multiple Mutation Indicators

Prevent Navigation

Show Success Message

Disable Buttons During Mutations

With Custom Predicate

Combined with Query Fetching

Exact Mutation Key Match

Notes

  • The hook uses useMutationState internally to track mutations
  • Only counts mutations with status: 'pending' by default
  • Returns 0 when no mutations are pending
  • Updates automatically when mutations start or complete
  • Can be used multiple times with different filters in the same component
  • Useful for implementing global or section-specific save indicators
  • The count includes all pending mutations that match the filters
  • Does not cause re-renders unless the count actually changes
  • Internally implemented using useMutationState with a pending status filter