Open History to see the last commit
1---
2id: useIsFetching
3title: useIsFetching
4---
5β
6```ts
7function useIsFetching(filters?: QueryFilters<readonly unknown[]>, queryClient?: QueryClient): number;
8```
9β
10Defined in: [packages/preact-query/src/useIsFetching.ts:41](https://github.com/TanStack/query/blob/main/packages/preact-query/src/useIsFetching.ts#L41)
11β
12The `useIsFetching` hook returns the `number` of the queries that your application is loading or fetching in
13the background (useful for app-wide loading indicators).
14β
15## Parameters
16β
17### filters?
18β
19[`QueryFilters`](../interfaces/QueryFilters.md)\<readonly `unknown`[]\>
20β
21The [QueryFilters](../interfaces/QueryFilters.md) to narrow down the matched queries.
22β
23<a id="filters-properties"></a>
24β
25#### `filters` properties
26β
27| Property | Type | Default value | Description |
28| ------ | ------ | ------ | ------ |
29| <a id="filters-property-exact"></a> `exact?` | `boolean` | `undefined` | Match query key exactly |
30| <a id="filters-property-fetchstatus"></a> `fetchStatus?` | `"fetching"` \| `"paused"` \| `"idle"` | `undefined` | Include queries matching their fetchStatus |
31| <a id="filters-property-predicate"></a> `predicate?` | (`query`: [`Query`](../classes/Query.md)) => `boolean` | `undefined` | Include queries matching this predicate function |
32| <a id="filters-property-querykey"></a> `queryKey?` | `TQueryKey` \| `TuplePrefixes`\<`TQueryKey`\> | `undefined` | Include queries matching this query key |
33| <a id="filters-property-stale"></a> `stale?` | `boolean` | `undefined` | Include or exclude stale queries |
34| <a id="filters-property-type"></a> `type?` | `QueryTypeFilter` | `'all'` | Filter to active queries, inactive queries or all queries |
35β
36### queryClient?
37β
38[`QueryClient`](../classes/QueryClient.md)
39β
40Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
41be used.
42β
43## Returns
44β
45`number`
46β
47Will be the `number` of the queries that your application is currently loading or fetching in the
48background.
49β
50## Examples
51β
52```tsx
53import { useIsFetching } from '@tanstack/preact-query'
54β
55function PostsFetchingIndicator() {
56 // How many queries matching the posts prefix are fetching?
57 const isFetchingPosts = useIsFetching({ queryKey: ['posts'] })
58β
59 return isFetchingPosts ? <span>Refreshing posts...</span> : null
60}
61```
62β
63A global loading indicator for any query fetching in the background, not just the ones on screen:
64```tsx
65import { useIsFetching } from '@tanstack/preact-query'
66β
67function GlobalLoadingIndicator() {
68 const isFetching = useIsFetching()
69β
70 return isFetching ? (
71 <div>Queries are fetching in the background...</div>
72 ) : null
73}
74```