Open History to see the last commit
1---
2id: useIsFetching
3title: useIsFetching
4---
5β
6<!-- DO NOT EDIT: this page is autogenerated from the type comments -->
7β
8```ts
9function useIsFetching(filters?: Omit<QueryFilters<readonly unknown[]>, "fetchStatus">, queryClient?: QueryClient): number;
10```
11β
12Defined in: [packages/preact-query/src/useIsFetching.ts:41](https://github.com/TanStack/query/blob/main/packages/preact-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`Omit`\<[`QueryFilters`](../interfaces/QueryFilters.md)\<readonly `unknown`[]\>, `"fetchStatus"`\>
22β
23The [QueryFilters](../interfaces/QueryFilters.md) to narrow down the matched queries.
24β
25<a id="filters-properties"></a>
26β
27#### `filters` properties
28β
29Built from [`QueryFilters`](../interfaces/QueryFilters.md#properties). See the type above for what it changes.
30β
31### queryClient?
32β
33[`QueryClient`](../classes/QueryClient.md)
34β
35Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
36be used.
37β
38## Returns
39β
40`number`
41β
42Will be the `number` of the queries that your application is currently loading or fetching in the
43background.
44β
45## Examples
46β
47```tsx
48import { useIsFetching } from '@tanstack/preact-query'
49β
50function PostsFetchingIndicator() {
51 // How many queries matching the posts prefix are fetching?
52 const isFetchingPosts = useIsFetching({ queryKey: ['posts'] })
53β
54 return isFetchingPosts ? <span>Refreshing posts...</span> : null
55}
56```
57β
58A global loading indicator for any query fetching in the background, not just the ones on screen:
59```tsx
60import { useIsFetching } from '@tanstack/preact-query'
61β
62function GlobalLoadingIndicator() {
63 const isFetching = useIsFetching()
64β
65 return isFetching ? (
66 <div>Queries are fetching in the background...</div>
67 ) : null
68}
69```