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