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

useIsFetching.md

56 lines1.6 KB

1---
2id: useIsFetching
3title: useIsFetching
4redirect_from:
5 - framework/solid/reference/useIsFetching
6---
7​
8```ts
9function useIsFetching(filters?: Accessor<QueryFilters<readonly unknown[]>>, queryClient?: Accessor<QueryClient>): Accessor<number>;
10```
11​
12Defined in: [packages/solid-query/src/useIsFetching.ts:27](https://github.com/TanStack/query/blob/main/packages/solid-query/src/useIsFetching.ts#L27)
13​
14The `useIsFetching` primitive returns the `number` of the queries that your application is loading or fetching
15in the background (useful for app-wide loading indicators).
16​
17## Parameters
18​
19### filters?
20​
21`Accessor`\<[`QueryFilters`](../interfaces/QueryFilters.md)\<readonly `unknown`[]\>\>
22​
23An accessor returning the [QueryFilters](../interfaces/QueryFilters.md) to narrow down the matched queries.
24​
25<a id="filters-properties"></a>
26​
27#### `filters` properties
28​
29Built from [`QueryFilters`](../interfaces/QueryFilters.md#properties). See the type above for what it changes.
30​
31### queryClient?
32​
33`Accessor`\<[`QueryClient`](../classes/QueryClient.md)\>
34​
35An accessor for a custom `QueryClient`. Otherwise, the one from the nearest context
36will be used.
37​
38## Returns
39​
40`Accessor`\<`number`\>
41​
42An accessor for the `number` of the queries that your application is currently loading or fetching
43in the background.
44​
45## Example
46​
47```tsx
48import { useIsFetching } from '@tanstack/solid-query'
49​
50function GlobalLoadingIndicator() {
51 // How many queries matching the posts prefix are fetching?
52 const isFetchingPosts = useIsFetching(() => ({ queryKey: ['posts'] }))
53​
54 return isFetchingPosts() > 0 ? <span>Loading posts...</span> : null
56```