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