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