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

useIsMutating.md

65 lines1.5 KB

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