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

useIsFetching.md

68 lines1.8 KB

1---
2id: useIsFetching
3title: useIsFetching
4redirect_from:
5 - framework/vue/reference/useIsFetching
6---
7​
8```ts
9function useIsFetching(fetchingFilters?: UseIsFetchingFilters, queryClient?: QueryClient): Ref<number>;
10```
11​
12Defined in: [packages/vue-query/src/useIsFetching.ts:54](https://github.com/TanStack/query/blob/main/packages/vue-query/src/useIsFetching.ts#L54)
13​
14The `useIsFetching` composable returns a `ref` to the `number` of the queries that your application is
15loading or fetching in the background (useful for app-wide loading indicators).
16​
17`fetchingFilters` may be a plain object, `MaybeRefDeep`, or a reactive getter (`() => ({ ... })`) β€” pass a
18getter if the filters themselves depend on other reactive state.
19​
20## Parameters
21​
22### fetchingFilters?
23​
24[`UseIsFetchingFilters`](../type-aliases/UseIsFetchingFilters.md) = `{}`
25​
26The [QueryFilters](../interfaces/QueryFilters.md) to narrow down the matched queries.
27​
28### queryClient?
29​
30[`QueryClient`](../classes/QueryClient.md)
31​
32Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`
33will be used.
34​
35## Returns
36​
37`Ref`\<`number`\>
38​
39A `ref` to the `number` of the queries that your application is currently loading or fetching in
40the background.
41​
42## Examples
43​
44```vue
45<script setup lang="ts">
46import { useIsFetching } from '@tanstack/vue-query'
47​
48// How many queries matching the posts prefix are fetching?
49const isFetchingPosts = useIsFetching({ queryKey: ['posts'] })
50</script>
51​
52<template>
53 <span v-if="isFetchingPosts">Refreshing posts...</span>
54</template>
55```
56​
57A global loading indicator for any query fetching in the background, not just the ones on screen:
58```vue
59<script setup lang="ts">
60import { useIsFetching } from '@tanstack/vue-query'
61​
62const isFetching = useIsFetching()
63</script>
64​
65<template>
66 <div v-if="isFetching">Queries are fetching in the background...</div>
67</template>
68```