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

useIsFetching.md

74 lines1.9 KB

1---
2id: useIsFetching
3title: useIsFetching
4---
5​
6<!-- DO NOT EDIT: this page is autogenerated from the type comments -->
7​
8```ts
9function useIsFetching(
10 host: ReactiveControllerHost,
11 filters?: Accessor<Omit<QueryFilters<readonly unknown[]>, "fetchStatus">>,
12 queryClient?: QueryClient
13): IsFetchingAccessor;
14```
15​
16Defined in: [packages/lit-query/src/useIsFetching.ts:141](https://github.com/TanStack/query/blob/main/packages/lit-query/src/useIsFetching.ts#L141)
17​
18Creates a Lit reactive controller that tracks how many matching queries are
19currently fetching.
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`\<[`QueryFilters`](../interfaces/QueryFilters.md)\<readonly `unknown`[]\>, `"fetchStatus"`\>\> = `{}`
37​
38Query filters, or a getter that returns query filters.
39​
40<a id="filters-properties"></a>
41​
42#### `filters` properties
43​
44Built from [`QueryFilters`](../interfaces/QueryFilters.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[`IsFetchingAccessor`](../type-aliases/IsFetchingAccessor.md)
56​
57An accessor for the current number of matching fetching queries.
58​
59## Example
60​
61```ts
62import { LitElement, html } from 'lit'
63import { useIsFetching } from '@tanstack/lit-query'
64​
65class TodosStatus extends LitElement {
66 private readonly todosFetching = useIsFetching(this, {
67 queryKey: ['todos'],
68 })
69​
70 render() {
71 return html`<span>${this.todosFetching()} active todo fetches</span>`
72 }
74```