Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

useIsFetching.md

71 lines1.9 KB

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): ReactiveValue<number>;
10```
11​
12Defined in: [packages/svelte-query/src/useIsFetching.svelte.ts:40](https://github.com/TanStack/query/blob/main/packages/svelte-query/src/useIsFetching.svelte.ts#L40)
13​
14The `useIsFetching` function returns the `number` of the queries that your application is loading or
15fetching in the background (useful for app-wide loading indicators).
16​
17## Parameters
18​
19### filters?
20​
21`Omit`\<[`QueryFilters`](../interfaces/QueryFilters.md)\<readonly `unknown`[]\>, `"fetchStatus"`\>
22​
23[QueryFilters](../interfaces/QueryFilters.md) to narrow down which queries to count. Omit to count every fetching
24query.
25​
26<a id="filters-properties"></a>
27​
28#### `filters` properties
29​
30Built from [`QueryFilters`](../interfaces/QueryFilters.md#properties). See the type above for what it changes.
31​
32### queryClient?
33​
34[`QueryClient`](../classes/QueryClient.md)
35​
36Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
37be used.
38​
39## Returns
40​
41`ReactiveValue`\<`number`\>
42​
43A reactive value β€” read `.current` to get how many matching queries are currently fetching.
44​
45## Examples
46​
47```svelte
48<script lang="ts">
49 import { useIsFetching } from '@tanstack/svelte-query'
50​
51 // How many queries matching the posts prefix are fetching?
52 const isFetchingPosts = useIsFetching({ queryKey: ['posts'] })
53</script>
54​
55{#if isFetchingPosts.current}
56 <span>Refreshing posts...</span>
57{/if}
58```
59​
60A global loading indicator for any query fetching in the background, not just the ones on screen:
61```svelte
62<script lang="ts">
63 import { useIsFetching } from '@tanstack/svelte-query'
64​
65 const isFetching = useIsFetching()
66</script>
67​
68{#if isFetching.current}
69 <div>Queries are fetching in the background...</div>
70{/if}
71```