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?: Omit<QueryFilters<readonly unknown[]>, "fetchStatus">, queryClient?: QueryClient): number;
12```
13β
14Defined in: [packages/react-query/src/useIsFetching.ts:40](https://github.com/TanStack/query/blob/main/packages/react-query/src/useIsFetching.ts#L40)
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`Omit`\<[`QueryFilters`](../interfaces/QueryFilters.md)\<readonly `unknown`[]\>, `"fetchStatus"`\>
24β
25The [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[`QueryClient`](../classes/QueryClient.md)
36β
37Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
38be used.
39β
40## Returns
41β
42`number`
43β
44Will be the `number` of the queries that your application is currently loading or fetching in the
45background.
46β
47## Examples
48β
49```tsx
50import { useIsFetching } from '@tanstack/react-query'
51β
52function PostsFetchingIndicator() {
53 // How many queries matching the posts prefix are fetching?
54 const isFetchingPosts = useIsFetching({ queryKey: ['posts'] })
55β
56 return isFetchingPosts ? <span>Refreshing posts...</span> : null
57}
58```
59β
60A global loading indicator for any query fetching in the background, not just the ones on screen:
61```tsx
62import { useIsFetching } from '@tanstack/react-query'
63β
64function GlobalLoadingIndicator() {
65 const isFetching = useIsFetching()
66β
67 return isFetching ? (
68 <div>Queries are fetching in the background...</div>
69 ) : null
70}
71```