MCPcopy
hub / github.com/TanStack/query / useIsFetching

Function useIsFetching

packages/svelte-query/src/useIsFetching.ts:7–30  ·  view source on GitHub ↗
(
  filters?: QueryFilters,
  queryClient?: QueryClient,
)

Source from the content-addressed store, hash-verified

5import type { QueryClient, QueryFilters } from '@tanstack/query-core'
6
7export function useIsFetching(
8 filters?: QueryFilters,
9 queryClient?: QueryClient,
10): Readable<number> {
11 const client = useQueryClient(queryClient)
12 const cache = client.getQueryCache()
13 // isFetching is the prev value initialized on mount *
14 let isFetching = client.isFetching(filters)
15
16 const { subscribe } = readable(isFetching, (set) => {
17 return cache.subscribe(
18 notifyManager.batchCalls(() => {
19 const newIsFetching = client.isFetching(filters)
20 if (isFetching !== newIsFetching) {
21 // * and update with each change
22 isFetching = newIsFetching
23 set(isFetching)
24 }
25 }),
26 )
27 })
28
29 return { subscribe }
30}

Callers

nothing calls this directly

Calls 5

setFunction · 0.85
getQueryCacheMethod · 0.80
useQueryClientFunction · 0.70
isFetchingMethod · 0.45
subscribeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…