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

useIsFetching.md

78 lines2.7 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?: QueryFilters<readonly unknown[]>, 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[`QueryFilters`](../interfaces/QueryFilters.md)\<readonly `unknown`[]\>
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​
30| Property | Type | Default value | Description |
31| ------ | ------ | ------ | ------ |
32| <a id="filters-property-exact"></a> `exact?` | `boolean` | `undefined` | Match query key exactly |
33| <a id="filters-property-fetchstatus"></a> `fetchStatus?` | `"fetching"` \| `"paused"` \| `"idle"` | `undefined` | Include queries matching their fetchStatus |
34| <a id="filters-property-predicate"></a> `predicate?` | (`query`: [`Query`](../classes/Query.md)) => `boolean` | `undefined` | Include queries matching this predicate function |
35| <a id="filters-property-querykey"></a> `queryKey?` | `TQueryKey` \| `TuplePrefixes`\<`TQueryKey`\> | `undefined` | Include queries matching this query key |
36| <a id="filters-property-stale"></a> `stale?` | `boolean` | `undefined` | Include or exclude stale queries |
37| <a id="filters-property-type"></a> `type?` | `QueryTypeFilter` | `'all'` | Filter to active queries, inactive queries or all queries |
38​
39### queryClient?
40​
41[`QueryClient`](../classes/QueryClient.md)
42​
43Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
44be used.
45​
46## Returns
47​
48`ReactiveValue`\<`number`\>
49​
50A reactive value β€” read `.current` to get how many matching queries are currently fetching.
51​
52## Examples
53​
54```svelte
55<script lang="ts">
56 import { useIsFetching } from '@tanstack/svelte-query'
57​
58 // How many queries matching the posts prefix are fetching?
59 const isFetchingPosts = useIsFetching({ queryKey: ['posts'] })
60</script>
61​
62{#if isFetchingPosts.current}
63 <span>Refreshing posts...</span>
64{/if}
65```
66​
67A global loading indicator for any query fetching in the background, not just the ones on screen:
68```svelte
69<script lang="ts">
70 import { useIsFetching } from '@tanstack/svelte-query'
71​
72 const isFetching = useIsFetching()
73</script>
74​
75{#if isFetching.current}
76 <div>Queries are fetching in the background...</div>
77{/if}
78```