( filters?: QueryFilters, queryClient?: QueryClient, )
| 5 | import type { QueryClient, QueryFilters } from '@tanstack/query-core' |
| 6 | |
| 7 | export 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 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…