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