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

useIsMutating.md

74 lines2.0 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(
10 host: ReactiveControllerHost,
11 filters?: Accessor<Omit<MutationFilters<unknown, Error, unknown, unknown>, "status">>,
12 queryClient?: QueryClient
13): IsMutatingAccessor;
14```
15​
16Defined in: [packages/lit-query/src/useIsMutating.ts:141](https://github.com/TanStack/query/blob/main/packages/lit-query/src/useIsMutating.ts#L141)
17​
18Creates a Lit reactive controller that tracks how many matching mutations are
19currently pending.
20​
21When `filters` is a function, it is re-read during host updates so the count
22can follow reactive host state. If `queryClient` is omitted, the controller
23resolves the client from the nearest connected `QueryClientProvider`.
24​
25## Parameters
26​
27### host
28​
29`ReactiveControllerHost`
30​
31The Lit reactive controller host that owns the cache
32subscription.
33​
34### filters?
35​
36[`Accessor`](../type-aliases/Accessor.md)\<`Omit`\<[`MutationFilters`](../interfaces/MutationFilters.md)\<`unknown`, `Error`, `unknown`, `unknown`\>, `"status"`\>\> = `{}`
37​
38Mutation filters, or a getter that returns mutation filters.
39​
40<a id="filters-properties"></a>
41​
42#### `filters` properties
43​
44Built from [`MutationFilters`](../interfaces/MutationFilters.md#properties). See the type above for what it changes.
45​
46### queryClient?
47​
48[`QueryClient`](../classes/QueryClient.md)
49​
50Optional explicit query client. Provide this for
51controllers that should not resolve a client from Lit context.
52​
53## Returns
54​
55[`IsMutatingAccessor`](../type-aliases/IsMutatingAccessor.md)
56​
57An accessor for the current number of matching pending mutations.
58​
59## Example
60​
61```ts
62import { LitElement, html } from 'lit'
63import { useIsMutating } from '@tanstack/lit-query'
64​
65class MutationStatus extends LitElement {
66 private readonly savesPending = useIsMutating(this, {
67 mutationKey: ['save-project'],
68 })
69​
70 render() {
71 return html`<span>${this.savesPending()} saves pending</span>`
72 }
74```