File size: 777 Bytes
74bd15c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | import { noop } from '@tanstack/query-core'
import { useQueryClient } from './QueryClientProvider'
import type {
DefaultError,
InfiniteData,
QueryClient,
QueryKey,
} from '@tanstack/query-core'
import type { UsePrefetchInfiniteQueryOptions } from './types'
export function usePrefetchInfiniteQuery<
TQueryFnData = unknown,
TError = DefaultError,
TData = InfiniteData<TQueryFnData>,
TQueryKey extends QueryKey = QueryKey,
TPageParam = unknown,
>(
options: UsePrefetchInfiniteQueryOptions<
TQueryFnData,
TError,
TData,
TQueryKey,
TPageParam
>,
queryClient?: QueryClient,
): void {
const client = useQueryClient(queryClient)
if (!client.getQueryState(options.queryKey)) {
void client.infiniteQuery(options).catch(noop)
}
}
|