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

useIsMutating.md

55 lines1.5 KB

1---
2id: useIsMutating
3title: useIsMutating
4---
5​
6<!-- DO NOT EDIT: this page is autogenerated from the type comments -->
7​
8```ts
9function useIsMutating(filters?: Omit<MutationFilters<unknown, Error, unknown, unknown>, "status">, queryClient?: QueryClient): number;
10```
11​
12Defined in: [packages/preact-query/src/useMutationState.ts:33](https://github.com/TanStack/query/blob/main/packages/preact-query/src/useMutationState.ts#L33)
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`Omit`\<[`MutationFilters`](../interfaces/MutationFilters.md)\<`unknown`, `Error`, `unknown`, `unknown`\>, `"status"`\>
22​
23The [MutationFilters](../interfaces/MutationFilters.md) to narrow down the matched mutations.
24​
25<a id="filters-properties"></a>
26​
27#### `filters` properties
28​
29Built from [`MutationFilters`](../interfaces/MutationFilters.md#properties). See the type above for what it changes.
30​
31### queryClient?
32​
33[`QueryClient`](../classes/QueryClient.md)
34​
35Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
36be used.
37​
38## Returns
39​
40`number`
41​
42Will be the `number` of the mutations that your application currently has `pending`.
43​
44## Example
45​
46```tsx
47import { useIsMutating } from '@tanstack/preact-query'
48​
49function PostsMutatingIndicator() {
50 // How many mutations matching the posts prefix are in progress?
51 const isMutatingPosts = useIsMutating({ mutationKey: ['posts'] })
52​
53 return isMutatingPosts ? <span>Saving posts...</span> : null
55```