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

infiniteQueryOptions.md

224 lines8.9 KB

1---
2id: infiniteQueryOptions
3title: infiniteQueryOptions
4redirect_from:
5 - framework/solid/reference/infiniteQueryOptions
6---
7​
8## Overview
9​
10```ts
11function infiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>(options: InfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> & object): ReturnType<DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>> & QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>;
12function infiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>(options: InfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> & object): ReturnType<UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>> & QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>;
13```
14​
15- [`ReturnType<DefinedInitialDataInfiniteOptions>` β†’ `ReturnType<DefinedInitialDataInfiniteOptions> & QueryKeyWithDataTag`](#call-signature-1): You can generally pass everything to `infiniteQueryOptions` that you can also pass to `useInfiniteQuery`. These options can be shared across hooks and imperative APIs such as `queryClient.infiniteQuery`. `options.queryKey` is required and is the query key to generate options for.
16- [`ReturnType<UndefinedInitialDataInfiniteOptions>` β†’ `ReturnType<UndefinedInitialDataInfiniteOptions> & QueryKeyWithDataTag`](#call-signature-2): You can generally pass everything to `infiniteQueryOptions` that you can also pass to `useInfiniteQuery`. These options can be shared across hooks and imperative APIs such as `queryClient.infiniteQuery`. `options.queryKey` is required and is the query key to generate options for.
17​
18See also: [Parameters](#parameters-summary) Β· [Returns](#returns-summary)
19​
20<a id="call-signature-1"></a>
21​
22## Call Signature
23​
24```ts
25function infiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>(options: InfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> & object): ReturnType<DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>> & QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>;
26```
27​
28Defined in: [packages/solid-query/src/infiniteQueryOptions.ts:101](https://github.com/TanStack/query/blob/main/packages/solid-query/src/infiniteQueryOptions.ts#L101)
29​
30You can generally pass everything to `infiniteQueryOptions` that you can also pass to `useInfiniteQuery`.
31These options can be shared across hooks and imperative APIs such as `queryClient.infiniteQuery`.
32`options.queryKey` is required and is the query key to generate options for.
33​
34This overload is selected when `initialData` is set.
35​
36### Type Parameters
37​
38#### TQueryFnData
39​
40`TQueryFnData`
41​
42#### TError
43​
44`TError` = `Error`
45​
46#### TData
47​
48`TData` = [`InfiniteData`](../interfaces/InfiniteData.md)\<`TQueryFnData`, `unknown`\>
49​
50#### TQueryKey
51​
52`TQueryKey` *extends* readonly `unknown`[] = readonly `unknown`[]
53​
54#### TPageParam
55​
56`TPageParam` = `unknown`
57​
58### Parameters
59​
60#### options
61​
62[`InfiniteQueryOptions`](../interfaces/InfiniteQueryOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`, `TPageParam`\> & `object`
63​
64The [DefinedInitialDataInfiniteOptions](../type-aliases/DefinedInitialDataInfiniteOptions.md) to use β€” everything you can pass to `useInfiniteQuery`, with `initialData` set.
65​
66### Returns
67​
68`ReturnType`\<[`DefinedInitialDataInfiniteOptions`](../type-aliases/DefinedInitialDataInfiniteOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`, `TPageParam`\>\> & [`QueryKeyWithDataTag`](../type-aliases/QueryKeyWithDataTag.md)\<`TQueryKey`, [`InfiniteData`](../interfaces/InfiniteData.md)\<`TQueryFnData`\>, `TError`\>
69​
70The same options object, typed so that `queryKey` carries the inferred data type.
71​
72### See
73​
74[useInfiniteQuery](useInfiniteQuery.md) to run an infinite query with these options.
75​
76### Example
77​
78```tsx
79import { For } from 'solid-js'
80import { infiniteQueryOptions, useInfiniteQuery } from '@tanstack/solid-query'
81​
82const projectsOptions = infiniteQueryOptions({
83 queryKey: ['projects'],
84 queryFn: ({ pageParam }) => fetchProjects(pageParam),
85 initialPageParam: 0,
86 getNextPageParam: (lastPage) => lastPage.nextId,
87 initialData: { pages: [], pageParams: [] },
88})
89​
90function Projects() {
91 // `projectsQuery.data` is never `undefined`, thanks to `initialData` β€” even if a refetch fails, so the
92 // list stays visible alongside the error.
93 const projectsQuery = useInfiniteQuery(() => projectsOptions)
94​
95 return (
96 <div>
97 {projectsQuery.isError ? <span>Error: {projectsQuery.error.message}</span> : null}
98 <ul>
99 <For each={projectsQuery.data.pages}>
100 {(page) => <For each={page.projects}>{(p) => <li>{p.name}</li>}</For>}
101 </For>
102 </ul>
103 </div>
104 )
106```
107​
108<a id="call-signature-2"></a>
109​
110## Call Signature
111​
112```ts
113function infiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>(options: InfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> & object): ReturnType<UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>> & QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>;
114```
115​
116Defined in: [packages/solid-query/src/infiniteQueryOptions.ts:168](https://github.com/TanStack/query/blob/main/packages/solid-query/src/infiniteQueryOptions.ts#L168)
117​
118You can generally pass everything to `infiniteQueryOptions` that you can also pass to `useInfiniteQuery`.
119These options can be shared across hooks and imperative APIs such as `queryClient.infiniteQuery`.
120`options.queryKey` is required and is the query key to generate options for.
121​
122### Type Parameters
123​
124#### TQueryFnData
125​
126`TQueryFnData`
127​
128#### TError
129​
130`TError` = `Error`
131​
132#### TData
133​
134`TData` = [`InfiniteData`](../interfaces/InfiniteData.md)\<`TQueryFnData`, `unknown`\>
135​
136#### TQueryKey
137​
138`TQueryKey` *extends* readonly `unknown`[] = readonly `unknown`[]
139​
140#### TPageParam
141​
142`TPageParam` = `unknown`
143​
144### Parameters
145​
146#### options
147​
148[`InfiniteQueryOptions`](../interfaces/InfiniteQueryOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`, `TPageParam`\> & `object`
149​
150The [UndefinedInitialDataInfiniteOptions](../type-aliases/UndefinedInitialDataInfiniteOptions.md) to use β€” everything you can pass to `useInfiniteQuery`.
151​
152### Returns
153​
154`ReturnType`\<[`UndefinedInitialDataInfiniteOptions`](../type-aliases/UndefinedInitialDataInfiniteOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`, `TPageParam`\>\> & [`QueryKeyWithDataTag`](../type-aliases/QueryKeyWithDataTag.md)\<`TQueryKey`, [`InfiniteData`](../interfaces/InfiniteData.md)\<`TQueryFnData`\>, `TError`\>
155​
156The same options object, typed so that `queryKey` carries the inferred data type.
157​
158### See
159​
160[useInfiniteQuery](useInfiniteQuery.md) to run an infinite query with these options.
161​
162### Example
163​
164A parameterized factory, so the same options object can be reused per `postId`:
165```tsx
166import { For, Match, Switch } from 'solid-js'
167import { infiniteQueryOptions, useInfiniteQuery } from '@tanstack/solid-query'
168​
169const commentsOptions = (postId: string) =>
170 infiniteQueryOptions({
171 queryKey: ['post', postId, 'comments'],
172 queryFn: ({ pageParam }) => fetchComments(postId, pageParam),
173 initialPageParam: 0,
174 getNextPageParam: (lastPage) => lastPage.nextId,
175 })
176​
177function Comments(props: { postId: string }) {
178 const commentsQuery = useInfiniteQuery(() => commentsOptions(props.postId))
179​
180 return (
181 <Switch>
182 <Match when={commentsQuery.isPending}>Loading...</Match>
183 <Match when={commentsQuery.isError}>Error: {commentsQuery.error.message}</Match>
184 <Match when={commentsQuery.isSuccess}>
185 <ul>
186 <For each={commentsQuery.data.pages}>
187 {(page) => <For each={page.comments}>{(c) => <li>{c.text}</li>}</For>}
188 </For>
189 </ul>
190 </Match>
191 </Switch>
192 )
194```
195​
196<a id="parameters-summary"></a>
197​
198## Parameters
199​
200### options
201​
202[`InfiniteQueryOptions`](../interfaces/InfiniteQueryOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`, `TPageParam`\> & `object`
203​
204The [UndefinedInitialDataInfiniteOptions](../type-aliases/UndefinedInitialDataInfiniteOptions.md) to use β€” everything you can pass to `useInfiniteQuery`.
205​
206<a id="options-properties"></a>
207​
208#### `options` properties
209​
210Built from [`InfiniteQueryOptions`](../interfaces/InfiniteQueryOptions.md#properties). See the type above for what it changes.
211​
212<a id="returns-summary"></a>
213​
214## Returns
215​
216`ReturnType`\<[`UndefinedInitialDataInfiniteOptions`](../type-aliases/UndefinedInitialDataInfiniteOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`, `TPageParam`\>\> & [`QueryKeyWithDataTag`](../type-aliases/QueryKeyWithDataTag.md)\<`TQueryKey`, [`InfiniteData`](../interfaces/InfiniteData.md)\<`TQueryFnData`\>, `TError`\>
217​
218The same options object, typed so that `queryKey` carries the inferred data type.
219​
220<a id="result-properties"></a>
221​
222### Result properties
223​
224Built from [`InfiniteQueryOptions`](../interfaces/InfiniteQueryOptions.md#properties), [`QueryKeyWithDataTag`](../type-aliases/QueryKeyWithDataTag.md#properties). See the type above for what it changes.