Capítulo 67 de 80

Chapter 67: useIsMutating

Core Idea

The mutation-side mirror of useIsFetching — reactive count of in-flight mutations, optionally scoped by mutationKey, for the same app-wide-loading-indicator use case.

Key Concepts

  • No arguments: counts every currently-executing mutation.
  • filters (MutationFilters): scope to a mutationKey prefix or predicate — e.g. useIsMutating({ mutationKey: ['posts'] }).
  • queryClient: optional explicit override.

Code Examples

const isMutating = useIsMutating()
const isMutatingPosts = useIsMutating({ mutationKey: ['posts'] })
  • What it demonstrates: global vs. key-scoped mutation-activity indicators.

Key Takeaways

  1. Pairs naturally with useIsFetching for a single "app is busy" indicator covering both reads and writes.

Connects To

  • useIsFetching: the query-side equivalent with identical shape.
  • QueryClient: isMutating(), the imperative equivalent.