MCPcopy Create free account
hub / github.com/TanStack/query / useIsFetching

Function useIsFetching

packages/vue-query/src/useIsFetching.ts:11–44  ·  view source on GitHub ↗
(
  fetchingFilters: QueryFilters = {},
  queryClient?: QueryClient,
)

Source from the content-addressed store, hash-verified

9export type QueryFilters = MaybeRefDeep<QF> | (() => MaybeRefDeep<QF>)
10
11export function useIsFetching(
12 fetchingFilters: QueryFilters = {},
13 queryClient?: QueryClient,
14): Ref<number> {
15 if (process.env.NODE_ENV === 'development') {
16 if (!getCurrentScope()) {
17 console.warn(
18 'vue-query composable like "useQuery()" should only be used inside a "setup()" function or a running effect scope. They might otherwise lead to memory leaks.',
19 )
20 }
21 }
22
23 const client = queryClient || useQueryClient()
24
25 const isFetching = ref()
26
27 const listener = () => {
28 const resolvedFilters =
29 typeof fetchingFilters === 'function'
30 ? fetchingFilters()
31 : fetchingFilters
32 isFetching.value = client.isFetching(cloneDeepUnref(resolvedFilters))
33 }
34
35 const unsubscribe = client.getQueryCache().subscribe(listener)
36
37 watchEffect(listener)
38
39 onScopeDispose(() => {
40 unsubscribe()
41 })
42
43 return isFetching
44}

Callers 1

Calls 5

useQueryClientFunction · 0.90
getQueryCacheMethod · 0.80
unsubscribeFunction · 0.70
refFunction · 0.50
subscribeMethod · 0.45

Tested by

no test coverage detected