Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

useIsMutating.md

62 lines2.1 KB

1---
2id: useIsMutating
3title: useIsMutating
4redirect_from:
5 - framework/react/reference/useIsMutating
6---
7​
8<!-- DO NOT EDIT: this page is autogenerated from the type comments -->
9​
10```ts
11function useIsMutating(filters?: MutationFilters<unknown, Error, unknown, unknown>, queryClient?: QueryClient): number;
12```
13​
14Defined in: [packages/react-query/src/useMutationState.ts:33](https://github.com/TanStack/query/blob/main/packages/react-query/src/useMutationState.ts#L33)
15​
16The `useIsMutating` hook returns the `number` of mutations that your application currently has `pending`
17(useful for app-wide loading indicators).
18​
19## Parameters
20​
21### filters?
22​
23[`MutationFilters`](../interfaces/MutationFilters.md)\<`unknown`, `Error`, `unknown`, `unknown`\>
24​
25The [MutationFilters](../interfaces/MutationFilters.md) to narrow down the matched mutations.
26​
27<a id="filters-properties"></a>
28​
29#### `filters` properties
30​
31| Property | Type | Description |
32| ------ | ------ | ------ |
33| <a id="filters-property-exact"></a> `exact?` | `boolean` | Match mutation key exactly |
34| <a id="filters-property-mutationkey"></a> `mutationKey?` | readonly `unknown`[] | Include mutations matching this mutation key |
35| <a id="filters-property-predicate"></a> `predicate?` | (`mutation`: [`Mutation`](../classes/Mutation.md)\<`TData`, `TError`, `TVariables`, `TOnMutateResult`\>) => `boolean` | Include mutations matching this predicate function |
36| <a id="filters-property-status"></a> `status?` | `"error"` \| `"pending"` \| `"success"` \| `"idle"` | Filter by mutation status |
37​
38### queryClient?
39​
40[`QueryClient`](../classes/QueryClient.md)
41​
42Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
43be used.
44​
45## Returns
46​
47`number`
48​
49Will be the `number` of the mutations that your application currently has `pending`.
50​
51## Example
52​
53```tsx
54import { useIsMutating } from '@tanstack/react-query'
55​
56function PostsMutatingIndicator() {
57 // How many mutations matching the posts prefix are in progress?
58 const isMutatingPosts = useIsMutating({ mutationKey: ['posts'] })
59​
60 return isMutatingPosts ? <span>Saving posts...</span> : null
62```