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

useIsFetching.md

71 lines1.8 KB

1---
2id: useIsFetching
3title: useIsFetching
4---
5​
6```ts
7function useIsFetching(
8 host: ReactiveControllerHost,
9 filters?: Accessor<QueryFilters<readonly unknown[]>>,
10 queryClient?: QueryClient): IsFetchingAccessor;
11```
12​
13Defined in: [packages/lit-query/src/useIsFetching.ts:141](https://github.com/TanStack/query/blob/main/packages/lit-query/src/useIsFetching.ts#L141)
14​
15Creates a Lit reactive controller that tracks how many matching queries are
16currently fetching.
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)\<[`QueryFilters`](../interfaces/QueryFilters.md)\<readonly `unknown`[]\>\> = `{}`
34​
35Query filters, or a getter that returns query filters.
36​
37<a id="filters-properties"></a>
38​
39#### `filters` properties
40​
41Built from [`QueryFilters`](../interfaces/QueryFilters.md#properties). See the type above for what it changes.
42​
43### queryClient?
44​
45[`QueryClient`](../classes/QueryClient.md)
46​
47Optional explicit query client. Provide this for
48controllers that should not resolve a client from Lit context.
49​
50## Returns
51​
52[`IsFetchingAccessor`](../type-aliases/IsFetchingAccessor.md)
53​
54An accessor for the current number of matching fetching queries.
55​
56## Example
57​
58```ts
59import { LitElement, html } from 'lit'
60import { useIsFetching } from '@tanstack/lit-query'
61​
62class TodosStatus extends LitElement {
63 private readonly todosFetching = useIsFetching(this, {
64 queryKey: ['todos'],
65 })
66​
67 render() {
68 return html`<span>${this.todosFetching()} active todo fetches</span>`
69 }
71```