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

useIsMutating.md

49 lines1.3 KB

1---
2id: useIsMutating
3title: useIsMutating
4redirect_from:
5 - framework/react/reference/useIsMutating
6---
7​
8```ts
9function useIsMutating(filters?: MutationFilters<unknown, Error, unknown, unknown>, queryClient?: QueryClient): number;
10```
11​
12Defined in: [packages/react-query/src/useMutationState.ts:35](https://github.com/TanStack/query/blob/main/packages/react-query/src/useMutationState.ts#L35)
13​
14The `useIsMutating` hook returns the `number` of mutations that your application currently has `pending`
15(useful for app-wide loading indicators).
16​
17## Parameters
18​
19### filters?
20​
21[`MutationFilters`](../interfaces/MutationFilters.md)\<`unknown`, `Error`, `unknown`, `unknown`\>
22​
23The [MutationFilters](../interfaces/MutationFilters.md) to narrow down the matched mutations.
24​
25### queryClient?
26​
27[`QueryClient`](../classes/QueryClient.md)
28​
29Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
30be used.
31​
32## Returns
33​
34`number`
35​
36Will be the `number` of the mutations that your application currently has `pending`.
37​
38## Example
39​
40```tsx
41import { useIsMutating } from '@tanstack/react-query'
42​
43function PostsMutatingIndicator() {
44 // How many mutations matching the posts prefix are in progress?
45 const isMutatingPosts = useIsMutating({ mutationKey: ['posts'] })
46​
47 return isMutatingPosts ? <span>Saving posts...</span> : null
49```