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

useIsFetching.md

67 lines1.5 KB

1---
2id: useIsFetching
3title: useIsFetching
4---
5​
6# Function: useIsFetching()
7​
8```ts
9function useIsFetching(
10 host,
11 filters,
12 queryClient?): IsFetchingAccessor;
13```
14​
15Defined in: [packages/lit-query/src/useIsFetching.ts:147](https://github.com/TanStack/query/blob/main/packages/lit-query/src/useIsFetching.ts#L147)
16​
17Creates a Lit reactive controller that tracks how many matching queries are
18currently fetching.
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)\<`QueryFilters`\<readonly `unknown`[]\>\> = `{}`
36​
37Query filters, or a getter that returns query 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[`IsFetchingAccessor`](../type-aliases/IsFetchingAccessor.md)
49​
50An accessor for the current number of matching fetching queries.
51​
52## Example
53​
54```ts
55import { LitElement, html } from 'lit'
56import { useIsFetching } from '@tanstack/lit-query'
57​
58class TodosStatus extends LitElement {
59 private readonly todosFetching = useIsFetching(this, {
60 queryKey: ['todos'],
61 })
62​
63 render() {
64 return html`<span>${this.todosFetching()} active todo fetches</span>`
65 }
67```