Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

usePrefetchInfiniteQuery.tsx

28 lines734 Bytes

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