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:44](https://github.com/TanStack/query/blob/main/packages/react-query/src/useIsFetching.ts#L44)
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### queryClient?
26β
27[`QueryClient`](../classes/QueryClient.md)
28β
29Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
30be used.
31β
32## Returns
33β
34`number`
35β
36Will be the `number` of the queries that your application is currently loading or fetching in the
37background.
38β
39## Examples
40β
41```tsx
42import { useIsFetching } from '@tanstack/react-query'
43β
44function PostsFetchingIndicator() {
45 // How many queries matching the posts prefix are fetching?
46 const isFetchingPosts = useIsFetching({ queryKey: ['posts'] })
47β
48 return isFetchingPosts ? <span>Refreshing posts...</span> : null
49}
50```
51β
52A global loading indicator for any query fetching in the background, not just the ones on screen:
53```tsx
54import { useIsFetching } from '@tanstack/react-query'
55β
56function GlobalLoadingIndicator() {
57 const isFetching = useIsFetching()
58β
59 return isFetching ? (
60 <div>Queries are fetching in the background...</div>
61 ) : null
62}
63```