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

usePrefetchInfiniteQuery.tsx

33 lines777 Bytes

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