Open History to see the last commit
1---
2id: infiniteQueryOptions
3title: infiniteQueryOptions
4---
5β
6## Overview
7β
8```ts
9function infiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>(options: DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> & QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>;
10function infiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>(options: UnusedSkipTokenInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): UnusedSkipTokenInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> & QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>;
11function infiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>(options: UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> & QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>;
12```
13β
14- [`DefinedInitialDataInfiniteOptions` β `DefinedInitialDataInfiniteOptions & QueryKeyWithDataTag`](#call-signature-1): You can generally pass everything to `infiniteQueryOptions` that you can also pass to `injectInfiniteQuery`. These options can be shared across functions and imperative APIs such as `queryClient.fetchInfiniteQuery`. `options.queryKey` is required and is the query key to generate options for.
15- [`UnusedSkipTokenInfiniteOptions` β `UnusedSkipTokenInfiniteOptions & QueryKeyWithDataTag`](#call-signature-2): You can generally pass everything to `infiniteQueryOptions` that you can also pass to `injectInfiniteQuery`. These options can be shared across functions and imperative APIs such as `queryClient.fetchInfiniteQuery`. `options.queryKey` is required and is the query key to generate options for.
16- [`UndefinedInitialDataInfiniteOptions` β `UndefinedInitialDataInfiniteOptions & QueryKeyWithDataTag`](#call-signature-3): You can generally pass everything to `infiniteQueryOptions` that you can also pass to `injectInfiniteQuery`. These options can be shared across functions and imperative APIs such as `queryClient.fetchInfiniteQuery`. `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: DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> & QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>;
26```
27β
28Defined in: [packages/angular-query-experimental/src/infinite-query-options.ts:176](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/infinite-query-options.ts#L176)
29β
30You can generally pass everything to `infiniteQueryOptions` that you can also pass to
31`injectInfiniteQuery`. These options can be shared across functions and imperative APIs such as
32`queryClient.fetchInfiniteQuery`. `options.queryKey` is required and is the query key to generate options
33for.
34β
35This overload is selected when `initialData` is set.
36β
37### Type Parameters
38β
39#### TQueryFnData
40β
41`TQueryFnData`
42β
43#### TError
44β
45`TError` = `Error`
46β
47#### TData
48β
49`TData` = [`InfiniteData`](../interfaces/InfiniteData.md)\<`TQueryFnData`, `unknown`\>
50β
51#### TQueryKey
52β
53`TQueryKey` *extends* readonly `unknown`[] = readonly `unknown`[]
54β
55#### TPageParam
56β
57`TPageParam` = `unknown`
58β
59### Parameters
60β
61#### options
62β
63[`DefinedInitialDataInfiniteOptions`](../type-aliases/DefinedInitialDataInfiniteOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`, `TPageParam`\>
64β
65The [DefinedInitialDataInfiniteOptions](../type-aliases/DefinedInitialDataInfiniteOptions.md) to use β everything you can pass to
66`injectInfiniteQuery`, with `initialData` set.
67β
68### Returns
69β
70[`DefinedInitialDataInfiniteOptions`](../type-aliases/DefinedInitialDataInfiniteOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`, `TPageParam`\> & [`QueryKeyWithDataTag`](../type-aliases/QueryKeyWithDataTag.md)\<`TQueryKey`, [`InfiniteData`](../interfaces/InfiniteData.md)\<`TQueryFnData`\>, `TError`\>
71β
72The same options object, typed so that `queryKey` carries the inferred data type.
73β
74### Remarks
75β
76See [injectInfiniteQuery](injectInfiniteQuery.md) for examples that fetch further pages, from a button click or
77automatically as the user scrolls.
78β
79### See
80β
81[injectInfiniteQuery](injectInfiniteQuery.md) to run an infinite query with these options.
82β
83### Example
84β
85```angular-ts
86import { infiniteQueryOptions, injectInfiniteQuery } from '@tanstack/angular-query-experimental'
87β
88export const projectsOptions = infiniteQueryOptions({
89 queryKey: ['projects'],
90 queryFn: ({ pageParam }) => fetchProjects(pageParam),
91 initialPageParam: 0,
92 getNextPageParam: (lastPage) => lastPage.nextId,
93 initialData: { pages: [], pageParams: [] },
94})
95β
96@Component({
97 selector: 'projects',
98 template: `
99 <!-- `projectsQuery.data()` is never `undefined`, thanks to `initialData` β even if a
100 refetch fails, so the list stays visible alongside the error. -->
101 <ul>
102 @for (page of projectsQuery.data().pages; track $index) {
103 @for (project of page.projects; track project.id) {
104 <li>{{ project.name }}</li>
105 }
106 }
107 </ul>
108 `,
109})
110export class Projects {
111 readonly projectsQuery = injectInfiniteQuery(() => projectsOptions)
112}
113```
114β
115<a id="call-signature-2"></a>
116β
117## Call Signature
118β
119```ts
120function infiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>(options: UnusedSkipTokenInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): UnusedSkipTokenInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> & QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>;
121```
122β
123Defined in: [packages/angular-query-experimental/src/infinite-query-options.ts:247](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/infinite-query-options.ts#L247)
124β
125You can generally pass everything to `infiniteQueryOptions` that you can also pass to
126`injectInfiniteQuery`. These options can be shared across functions and imperative APIs such as
127`queryClient.fetchInfiniteQuery`. `options.queryKey` is required and is the query key to generate options
128for.
129β
130### Type Parameters
131β
132#### TQueryFnData
133β
134`TQueryFnData`
135β
136#### TError
137β
138`TError` = `Error`
139β
140#### TData
141β
142`TData` = [`InfiniteData`](../interfaces/InfiniteData.md)\<`TQueryFnData`, `unknown`\>
143β
144#### TQueryKey
145β
146`TQueryKey` *extends* readonly `unknown`[] = readonly `unknown`[]
147β
148#### TPageParam
149β
150`TPageParam` = `unknown`
151β
152### Parameters
153β
154#### options
155β
156[`UnusedSkipTokenInfiniteOptions`](../type-aliases/UnusedSkipTokenInfiniteOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`, `TPageParam`\>
157β
158The [UnusedSkipTokenInfiniteOptions](../type-aliases/UnusedSkipTokenInfiniteOptions.md) to use β everything you can pass to
159`injectInfiniteQuery`.
160β
161### Returns
162β
163[`UnusedSkipTokenInfiniteOptions`](../type-aliases/UnusedSkipTokenInfiniteOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`, `TPageParam`\> & [`QueryKeyWithDataTag`](../type-aliases/QueryKeyWithDataTag.md)\<`TQueryKey`, [`InfiniteData`](../interfaces/InfiniteData.md)\<`TQueryFnData`\>, `TError`\>
164β
165The same options object, typed so that `queryKey` carries the inferred data type.
166β
167### Remarks
168β
169See [injectInfiniteQuery](injectInfiniteQuery.md) for examples that fetch further pages, from a button click or
170automatically as the user scrolls.
171β
172### See
173β
174[injectInfiniteQuery](injectInfiniteQuery.md) to run an infinite query with these options.
175β
176### Example
177β
178A parameterized factory, so the same options object can be reused per `postId`:
179```angular-ts
180import { infiniteQueryOptions, injectInfiniteQuery } from '@tanstack/angular-query-experimental'
181β
182export const commentsOptions = (postId: string) =>
183 infiniteQueryOptions({
184 queryKey: ['post', postId, 'comments'],
185 queryFn: ({ pageParam }) => fetchComments(postId, pageParam),
186 initialPageParam: 0,
187 getNextPageParam: (lastPage) => lastPage.nextId,
188 })
189β
190@Component({
191 selector: 'comments',
192 template: `
193 @if (commentsQuery.isPending()) {
194 Loading...
195 } @else if (commentsQuery.isError()) {
196 <span>Error: {{ commentsQuery.error()?.message }}</span>
197 } @else {
198 <ul>
199 @for (page of commentsQuery.data().pages; track $index) {
200 @for (comment of page.comments; track comment.id) {
201 <li>{{ comment.text }}</li>
202 }
203 }
204 </ul>
205 }
206 `,
207})
208export class Comments {
209 readonly postId = signal('1')
210 readonly commentsQuery = injectInfiniteQuery(() => commentsOptions(this.postId()))
211}
212```
213β
214<a id="call-signature-3"></a>
215β
216## Call Signature
217β
218```ts
219function infiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>(options: UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> & QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>;
220```
221β
222Defined in: [packages/angular-query-experimental/src/infinite-query-options.ts:318](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/infinite-query-options.ts#L318)
223β
224You can generally pass everything to `infiniteQueryOptions` that you can also pass to
225`injectInfiniteQuery`. These options can be shared across functions and imperative APIs such as
226`queryClient.fetchInfiniteQuery`. `options.queryKey` is required and is the query key to generate options
227for.
228β
229### Type Parameters
230β
231#### TQueryFnData
232β
233`TQueryFnData`
234β
235#### TError
236β
237`TError` = `Error`
238β
239#### TData
240β
241`TData` = [`InfiniteData`](../interfaces/InfiniteData.md)\<`TQueryFnData`, `unknown`\>
242β
243#### TQueryKey
244β
245`TQueryKey` *extends* readonly `unknown`[] = readonly `unknown`[]
246β
247#### TPageParam
248β
249`TPageParam` = `unknown`
250β
251### Parameters
252β
253#### options
254β
255[`UndefinedInitialDataInfiniteOptions`](../type-aliases/UndefinedInitialDataInfiniteOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`, `TPageParam`\>
256β
257The [UndefinedInitialDataInfiniteOptions](../type-aliases/UndefinedInitialDataInfiniteOptions.md) to use β everything you can pass to
258`injectInfiniteQuery`.
259β
260### Returns
261β
262[`UndefinedInitialDataInfiniteOptions`](../type-aliases/UndefinedInitialDataInfiniteOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`, `TPageParam`\> & [`QueryKeyWithDataTag`](../type-aliases/QueryKeyWithDataTag.md)\<`TQueryKey`, [`InfiniteData`](../interfaces/InfiniteData.md)\<`TQueryFnData`\>, `TError`\>
263β
264The same options object, typed so that `queryKey` carries the inferred data type.
265β
266### Remarks
267β
268See [injectInfiniteQuery](injectInfiniteQuery.md) for examples that fetch further pages (from a button click or
269automatically as the user scrolls) and that use `skipToken` to disable the query until `postId` is set.
270β
271### See
272β
273[injectInfiniteQuery](injectInfiniteQuery.md) to run an infinite query with these options.
274β
275### Example
276β
277A parameterized factory, so the same options object can be reused per `postId`:
278```angular-ts
279import { infiniteQueryOptions, injectInfiniteQuery } from '@tanstack/angular-query-experimental'
280β
281export const commentsOptions = (postId: string) =>
282 infiniteQueryOptions({
283 queryKey: ['post', postId, 'comments'],
284 queryFn: ({ pageParam }) => fetchComments(postId, pageParam),
285 initialPageParam: 0,
286 getNextPageParam: (lastPage) => lastPage.nextId,
287 })
288β
289@Component({
290 selector: 'comments',
291 template: `
292 @if (commentsQuery.isPending()) {
293 Loading...
294 } @else if (commentsQuery.isError()) {
295 <span>Error: {{ commentsQuery.error()?.message }}</span>
296 } @else {
297 <ul>
298 @for (page of commentsQuery.data().pages; track $index) {
299 @for (comment of page.comments; track comment.id) {
300 <li>{{ comment.text }}</li>
301 }
302 }
303 </ul>
304 }
305 `,
306})
307export class Comments {
308 readonly postId = signal('1')
309 readonly commentsQuery = injectInfiniteQuery(() => commentsOptions(this.postId()))
310}
311```
312β
313<a id="parameters-summary"></a>
314β
315## Parameters
316β
317### options
318β
319[`UndefinedInitialDataInfiniteOptions`](../type-aliases/UndefinedInitialDataInfiniteOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`, `TPageParam`\>
320β
321The [UndefinedInitialDataInfiniteOptions](../type-aliases/UndefinedInitialDataInfiniteOptions.md) to use β everything you can pass to
322`injectInfiniteQuery`.
323β
324<a id="options-properties"></a>
325β
326#### `options` properties
327β
328Built from [`CreateInfiniteQueryOptions`](../interfaces/CreateInfiniteQueryOptions.md#properties). See the type above for what it changes.
329β
330<a id="returns-summary"></a>
331β
332## Returns
333β
334[`UndefinedInitialDataInfiniteOptions`](../type-aliases/UndefinedInitialDataInfiniteOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`, `TPageParam`\> & [`QueryKeyWithDataTag`](../type-aliases/QueryKeyWithDataTag.md)\<`TQueryKey`, [`InfiniteData`](../interfaces/InfiniteData.md)\<`TQueryFnData`\>, `TError`\>
335β
336The same options object, typed so that `queryKey` carries the inferred data type.
337β
338<a id="result-properties"></a>
339β
340### Result properties
341β
342Built from [`CreateInfiniteQueryOptions`](../interfaces/CreateInfiniteQueryOptions.md#properties), [`QueryKeyWithDataTag`](../type-aliases/QueryKeyWithDataTag.md#properties). See the type above for what it changes.