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 * @example
14 * ;```ts
15 * import { infiniteQueryOptions } from '@tanstack/lit-query'
16 *
17 * const projectsOptions = infiniteQueryOptions({
18 * queryKey: ['projects'],
19 * queryFn: ({ pageParam }) => fetchProjects(pageParam),
20 * initialPageParam: 0,
21 * getNextPageParam: (lastPage) => lastPage.nextCursor,
22 * })
23 * ```
24 *
25 * @param options - Infinite query options to preserve and brand.
26 * @returns The same options object with a typed `queryKey`.
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