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