Download react-query/packages/svelte-query/src/useIsFetching.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 945 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/packages/svelte-query/src/useIsFetching.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/packages/svelte-query/src/useIsFetching.ts
-
curl -L -o useIsFetching.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/packages/svelte-query/src/useIsFetching.ts
945 Bytes
| import { notifyManager } from '@tanstack/query-core' | |
| import { readable } from 'svelte/store' | |
| import { useQueryClient } from './useQueryClient.js' | |
| import type { Readable } from 'svelte/store' | |
| import type { QueryClient, QueryFilters } from '@tanstack/query-core' | |
| export function useIsFetching( | |
| filters?: QueryFilters, | |
| queryClient?: QueryClient, | |
| ): Readable<number> { | |
| const client = useQueryClient(queryClient) | |
| const cache = client.getQueryCache() | |
| // isFetching is the prev value initialized on mount * | |
| let isFetching = client.isFetching(filters) | |
| const { subscribe } = readable(isFetching, (set) => { | |
| return cache.subscribe( | |
| notifyManager.batchCalls(() => { | |
| const newIsFetching = client.isFetching(filters) | |
| if (isFetching !== newIsFetching) { | |
| // * and update with each change | |
| isFetching = newIsFetching | |
| set(isFetching) | |
| } | |
| }), | |
| ) | |
| }) | |
| return { subscribe } | |
| } | |