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

infiniteQueryOptions.ts

54 lines1.3 KB

1import type {
2 DataTag,
3 DefaultError,
4 InfiniteData,
5 InfiniteQueryObserverOptions,
6 QueryKey,
7} from '@tanstack/query-core'
8​
9/**
10 * Brands infinite query options so the `queryKey` carries the infinite query
11 * data and error types across TanStack Query APIs.
12 *
13 * @param options - Infinite query options to preserve and brand.
14 * @returns The same options object with a typed `queryKey`.
15 *
16 * @example
17 * ```ts
18 * import { infiniteQueryOptions } from '@tanstack/lit-query'
19 *
20 * const projectsOptions = infiniteQueryOptions({
21 * queryKey: ['projects'],
22 * queryFn: ({ pageParam }) => fetchProjects(pageParam),
23 * initialPageParam: 0,
24 * getNextPageParam: (lastPage) => lastPage.nextCursor,
25 * })
26 * ```
27 */
28export function infiniteQueryOptions<
29 TQueryFnData = unknown,
30 TError = DefaultError,
31 TData = InfiniteData<TQueryFnData>,
32 TQueryKey extends QueryKey = QueryKey,
33 TPageParam = unknown,
34>(
35 options: InfiniteQueryObserverOptions<
36 TQueryFnData,
37 TError,
38 TData,
39 TQueryKey,
40 TPageParam
41 >,
42): InfiniteQueryObserverOptions<
43 TQueryFnData,
44 TError,
45 TData,
46 TQueryKey,
47 TPageParam
48> & {
49 queryKey: DataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>
51​
52export function infiniteQueryOptions(options: unknown) {
53 return options