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

useIsMutating.md

67 lines1.5 KB

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