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

useIsFetching.md

58 lines1.7 KB

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