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

useIsMutating.md

60 lines2.0 KB

1---
2id: useIsMutating
3title: useIsMutating
4---
5​
6```ts
7function useIsMutating(filters?: MutationFilters<unknown, Error, unknown, unknown>, queryClient?: QueryClient): ReactiveValue<number>;
8```
9​
10Defined in: [packages/svelte-query/src/useIsMutating.svelte.ts:26](https://github.com/TanStack/query/blob/main/packages/svelte-query/src/useIsMutating.svelte.ts#L26)
11​
12`useIsMutating` is an optional function that returns the `number` of mutations that your application is
13running (useful for app-wide loading indicators).
14​
15## Parameters
16​
17### filters?
18​
19[`MutationFilters`](../interfaces/MutationFilters.md)\<`unknown`, `Error`, `unknown`, `unknown`\>
20​
21[MutationFilters](../interfaces/MutationFilters.md) to narrow down which mutations to count.
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`ReactiveValue`\<`number`\>
44​
45A reactive value β€” read `.current` to get how many matching mutations are currently running.
46​
47## Example
48​
49```svelte
50<script lang="ts">
51 import { useIsMutating } from '@tanstack/svelte-query'
52​
53 // How many mutations matching the posts prefix are in progress?
54 const isMutatingPosts = useIsMutating({ mutationKey: ['posts'] })
55</script>
56​
57{#if isMutatingPosts.current}
58 <span>Saving posts...</span>
59{/if}
60```