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

Function useIsFetching

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

Source from the content-addressed store, hash-verified

53 * ```
54 */
55export function useIsFetching(
56 fetchingFilters: UseIsFetchingFilters = {},
57 queryClient?: QueryClient,
58): Ref<number> {
59 if (process.env.NODE_ENV === 'development') {
60 if (!getCurrentScope()) {
61 console.warn(
62 '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.',
63 )
64 }
65 }
66
67 const client = queryClient || useQueryClient()
68
69 const isFetching = ref()
70
71 const listener = () => {
72 const resolvedFilters =
73 typeof fetchingFilters === 'function'
74 ? fetchingFilters()
75 : fetchingFilters
76 isFetching.value = client.isFetching(cloneDeepUnref(resolvedFilters))
77 }
78
79 const unsubscribe = client.getQueryCache().subscribe(listener)
80
81 watchEffect(listener)
82
83 onScopeDispose(() => {
84 unsubscribe()
85 })
86
87 return isFetching
88}

Callers 2

Calls 5

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

Tested by

no test coverage detected