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