Open History to see the last commit
1---
2id: injectInfiniteQuery
3title: injectInfiniteQuery
4---
5β
6<!-- DO NOT EDIT: this page is autogenerated from the type comments -->
7β
8## Overview
9β
10```ts
11function injectInfiniteQuery<TQueryFnData, TError = Error, TData = InfiniteData<TQueryFnData, unknown>, TQueryKey extends readonly unknown[] = readonly unknown[], TPageParam = unknown>(injectInfiniteQueryFn: () => DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, options?: InjectInfiniteQueryOptions): DefinedCreateInfiniteQueryResult<TData, TError>;
12function injectInfiniteQuery<TQueryFnData, TError = Error, TData = InfiniteData<TQueryFnData, unknown>, TQueryKey extends readonly unknown[] = readonly unknown[], TPageParam = unknown>(injectInfiniteQueryFn: () => UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, options?: InjectInfiniteQueryOptions): CreateInfiniteQueryResult<TData, TError>;
13function injectInfiniteQuery<TQueryFnData, TError = Error, TData = InfiniteData<TQueryFnData, unknown>, TQueryKey extends readonly unknown[] = readonly unknown[], TPageParam = unknown>(injectInfiniteQueryFn: () => CreateInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, options?: InjectInfiniteQueryOptions): CreateInfiniteQueryResult<TData, TError>;
14```
15β
16- [`() => DefinedInitialDataInfiniteOptions` β `DefinedCreateInfiniteQueryResult`](#call-signature-1): The options for `injectInfiniteQuery` are identical to `injectQuery`, with the addition of `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`. Infinite queries can additively "load more" data onto an existing set of data, or "infinite scroll".
17- [`() => UndefinedInitialDataInfiniteOptions` β `CreateInfiniteQueryResult`](#call-signature-2): Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key. Infinite queries can additively "load more" data onto an existing set of data, or "infinite scroll".
18- [`() => CreateInfiniteQueryOptions` β `CreateInfiniteQueryResult`](#call-signature-3): This overload accepts the general [CreateInfiniteQueryOptions](../interfaces/CreateInfiniteQueryOptions.md) shape rather than the `initialData`-aware overloads above, so whether `data` is defined can't be inferred from the call site β useful when wrapping `injectInfiniteQuery` in your own helper function that forwards caller-provided options.
19β
20See also: [Parameters](#parameters-summary) Β· [Returns](#returns-summary)
21β
22<a id="call-signature-1"></a>
23β
24## Call Signature
25β
26```ts
27function injectInfiniteQuery<TQueryFnData, TError = Error, TData = InfiniteData<TQueryFnData, unknown>, TQueryKey extends readonly unknown[] = readonly unknown[], TPageParam = unknown>(injectInfiniteQueryFn: () => DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, options?: InjectInfiniteQueryOptions): DefinedCreateInfiniteQueryResult<TData, TError>;
28```
29β
30Defined in: [packages/angular-query-experimental/src/inject-infinite-query.ts:85](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-infinite-query.ts#L85)
31β
32The options for `injectInfiniteQuery` are identical to `injectQuery`, with the addition of
33`initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`. Infinite queries can
34additively "load more" data onto an existing set of data, or "infinite scroll".
35β
36This overload is selected when `initialData` is set on the options returned by `injectInfiniteQueryFn`,
37so the resulting `data` signal is never `undefined` (unless a `select` changes `TData` to include `undefined`).
38β
39### Type Parameters
40β
41#### TQueryFnData
42β
43`TQueryFnData`
44β
45#### TError
46β
47`TError` = `Error`
48β
49#### TData
50β
51`TData` = [`InfiniteData`](../interfaces/InfiniteData.md)\<`TQueryFnData`, `unknown`\>
52β
53#### TQueryKey
54β
55`TQueryKey` *extends* readonly `unknown`[] = readonly `unknown`[]
56β
57#### TPageParam
58β
59`TPageParam` = `unknown`
60β
61### Parameters
62β
63#### injectInfiniteQueryFn
64β
65() => [`DefinedInitialDataInfiniteOptions`](../type-aliases/DefinedInitialDataInfiniteOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`, `TPageParam`\>
66β
67A function returning the [DefinedInitialDataInfiniteOptions](../type-aliases/DefinedInitialDataInfiniteOptions.md) to use β
68everything you can pass to `injectInfiniteQuery`, with `initialData` set. Similar to `computed` from
69Angular, this function runs in the reactive context, so signals read inside it drive the query.
70β
71#### options?
72β
73[`InjectInfiniteQueryOptions`](../interfaces/InjectInfiniteQueryOptions.md)
74β
75Additional configuration.
76β
77### Returns
78β
79[`DefinedCreateInfiniteQueryResult`](../type-aliases/DefinedCreateInfiniteQueryResult.md)\<`TData`, `TError`\>
80β
81The same signals as `injectQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,
82`hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data().pages` and
83`data().pageParams` are also added, as long as a `select` doesn't change `TData` away from its default
84`InfiniteData<TQueryFnData>` shape.
85β
86### Remarks
87β
88Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default
89refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user
90actions, or add conditions like `hasNextPage() && !isFetching()`.
91β
92### See
93β
94[infiniteQueryOptions](infiniteQueryOptions.md) to share these options between `injectInfiniteQuery` and imperative APIs
95like `queryClient.fetchInfiniteQuery`.
96β
97### Example
98β
99```angular-ts
100@Component({
101 selector: 'projects',
102 template: `
103 <!-- `projectsQuery.data()` is never `undefined`, thanks to `initialData` β even if a
104 refetch fails, so the list stays visible alongside the error. -->
105 <ul>
106 @for (page of projectsQuery.data().pages; track $index) {
107 @for (project of page.projects; track project.id) {
108 <li>{{ project.name }}</li>
109 }
110 }
111 </ul>
112 `,
113})
114export class Projects {
115 readonly projectsQuery = injectInfiniteQuery(() => ({
116 queryKey: ['projects'],
117 queryFn: ({ pageParam }) => fetchProjects(pageParam),
118 initialPageParam: 0,
119 getNextPageParam: (lastPage) => lastPage.nextId,
120 initialData: { pages: [], pageParams: [] },
121 }))
122}
123```
124β
125<a id="call-signature-2"></a>
126β
127## Call Signature
128β
129```ts
130function injectInfiniteQuery<TQueryFnData, TError = Error, TData = InfiniteData<TQueryFnData, unknown>, TQueryKey extends readonly unknown[] = readonly unknown[], TPageParam = unknown>(injectInfiniteQueryFn: () => UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, options?: InjectInfiniteQueryOptions): CreateInfiniteQueryResult<TData, TError>;
131```
132β
133Defined in: [packages/angular-query-experimental/src/inject-infinite-query.ts:237](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-infinite-query.ts#L237)
134β
135Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a
136unique key. Infinite queries can additively "load more" data onto an existing set of data, or
137"infinite scroll".
138β
139### Type Parameters
140β
141#### TQueryFnData
142β
143`TQueryFnData`
144β
145#### TError
146β
147`TError` = `Error`
148β
149#### TData
150β
151`TData` = [`InfiniteData`](../interfaces/InfiniteData.md)\<`TQueryFnData`, `unknown`\>
152β
153#### TQueryKey
154β
155`TQueryKey` *extends* readonly `unknown`[] = readonly `unknown`[]
156β
157#### TPageParam
158β
159`TPageParam` = `unknown`
160β
161### Parameters
162β
163#### injectInfiniteQueryFn
164β
165() => [`UndefinedInitialDataInfiniteOptions`](../type-aliases/UndefinedInitialDataInfiniteOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`, `TPageParam`\>
166β
167A function returning the [UndefinedInitialDataInfiniteOptions](../type-aliases/UndefinedInitialDataInfiniteOptions.md) to use
168β everything you can pass to `injectInfiniteQuery`. Similar to `computed` from Angular, this function runs
169in the reactive context, so signals read inside it drive the query.
170β
171#### options?
172β
173[`InjectInfiniteQueryOptions`](../interfaces/InjectInfiniteQueryOptions.md)
174β
175Additional configuration.
176β
177### Returns
178β
179[`CreateInfiniteQueryResult`](../type-aliases/CreateInfiniteQueryResult.md)\<`TData`, `TError`\>
180β
181The same signals as `injectQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,
182`hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data().pages` and
183`data().pageParams` are also added, as long as a `select` doesn't change `TData` away from its default
184`InfiniteData<TQueryFnData>` shape.
185β
186### Remarks
187β
188Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default
189refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user
190actions, or add conditions like `hasNextPage() && !isFetching()`. This is the only overload that accepts
191`queryFn: skipToken`, shown below.
192β
193### See
194β
195[infiniteQueryOptions](infiniteQueryOptions.md) to share these options between `injectInfiniteQuery` and imperative APIs
196like `queryClient.fetchInfiniteQuery`.
197β
198### Examples
199β
200Fetching the next page from a button click:
201```angular-ts
202@Component({
203 selector: 'projects-list',
204 template: `
205 <ul>
206 @for (page of projectsQuery.data()?.pages; track $index) {
207 @for (project of page.projects; track project.id) {
208 <li>{{ project.name }}</li>
209 }
210 }
211 </ul>
212 <button
213 [disabled]="!projectsQuery.hasNextPage() || projectsQuery.isFetching()"
214 (click)="projectsQuery.fetchNextPage()"
215 >
216 Load More
217 </button>
218 `,
219})
220export class ProjectsList {
221 readonly projectsQuery = injectInfiniteQuery(() => ({
222 queryKey: ['projects'],
223 queryFn: ({ pageParam }) => fetchProjects(pageParam),
224 initialPageParam: 0,
225 getNextPageParam: (lastPage) => lastPage.nextId,
226 }))
227}
228```
229β
230Fetching the next page automatically as the user scrolls, using an `IntersectionObserver` on a sentinel
231element after the list:
232```angular-ts
233@Component({
234 selector: 'projects-list',
235 template: `
236 <ul>
237 @for (page of projectsQuery.data()?.pages; track $index) {
238 @for (project of page.projects; track project.id) {
239 <li>{{ project.name }}</li>
240 }
241 }
242 </ul>
243 <div #sentinel>{{ projectsQuery.isFetchingNextPage() ? 'Loading more...' : '' }}</div>
244 `,
245})
246export class ProjectsList {
247 readonly sentinel = viewChild<ElementRef<HTMLElement>>('sentinel')
248β
249 readonly projectsQuery = injectInfiniteQuery(() => ({
250 queryKey: ['projects'],
251 queryFn: ({ pageParam }) => fetchProjects(pageParam),
252 initialPageParam: 0,
253 getNextPageParam: (lastPage) => lastPage.nextId,
254 }))
255β
256 constructor() {
257 effect((onCleanup) => {
258 const sentinel = this.sentinel()?.nativeElement
259 if (
260 sentinel == null ||
261 !this.projectsQuery.hasNextPage() ||
262 this.projectsQuery.isFetching()
263 ) {
264 return
265 }
266β
267 const observer = new IntersectionObserver(([entry]) => {
268 if (entry?.isIntersecting) this.projectsQuery.fetchNextPage()
269 })
270 observer.observe(sentinel)
271β
272 onCleanup(() => observer.disconnect())
273 })
274 }
275}
276```
277β
278A query that's disabled, type safe, until `postId` is set β pass `skipToken` as `queryFn` instead of
279setting `enabled: false`:
280```angular-ts
281@Component({
282 selector: 'comments',
283 template: `
284 @if (postId() == null) {
285 Select a post
286 } @else if (commentsQuery.isPending()) {
287 Loading...
288 } @else if (commentsQuery.isError()) {
289 <span>Error: {{ commentsQuery.error()?.message }}</span>
290 } @else {
291 <ul>
292 @for (page of commentsQuery.data().pages; track $index) {
293 @for (comment of page.comments; track comment.id) {
294 <li>{{ comment.text }}</li>
295 }
296 }
297 </ul>
298 }
299 `,
300})
301export class Comments {
302 readonly postId = signal<string | undefined>(undefined)
303β
304 readonly commentsQuery = injectInfiniteQuery(() => ({
305 queryKey: ['post', this.postId(), 'comments'],
306 queryFn:
307 this.postId() != null
308 ? ({ pageParam }) => fetchComments(this.postId()!, pageParam)
309 : skipToken,
310 initialPageParam: 0,
311 getNextPageParam: (lastPage) => lastPage.nextId,
312 }))
313}
314```
315β
316<a id="call-signature-3"></a>
317β
318## Call Signature
319β
320```ts
321function injectInfiniteQuery<TQueryFnData, TError = Error, TData = InfiniteData<TQueryFnData, unknown>, TQueryKey extends readonly unknown[] = readonly unknown[], TPageParam = unknown>(injectInfiniteQueryFn: () => CreateInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, options?: InjectInfiniteQueryOptions): CreateInfiniteQueryResult<TData, TError>;
322```
323β
324Defined in: [packages/angular-query-experimental/src/inject-infinite-query.ts:264](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/inject-infinite-query.ts#L264)
325β
326This overload accepts the general [CreateInfiniteQueryOptions](../interfaces/CreateInfiniteQueryOptions.md) shape rather than the
327`initialData`-aware overloads above, so whether `data` is defined can't be inferred from the call site β
328useful when wrapping `injectInfiniteQuery` in your own helper function that forwards caller-provided
329options.
330β
331### Type Parameters
332β
333#### TQueryFnData
334β
335`TQueryFnData`
336β
337#### TError
338β
339`TError` = `Error`
340β
341#### TData
342β
343`TData` = [`InfiniteData`](../interfaces/InfiniteData.md)\<`TQueryFnData`, `unknown`\>
344β
345#### TQueryKey
346β
347`TQueryKey` *extends* readonly `unknown`[] = readonly `unknown`[]
348β
349#### TPageParam
350β
351`TPageParam` = `unknown`
352β
353### Parameters
354β
355#### injectInfiniteQueryFn
356β
357() => [`CreateInfiniteQueryOptions`](../interfaces/CreateInfiniteQueryOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`, `TPageParam`\>
358β
359A function that returns infinite query options. Similar to `computed` from
360Angular, this function runs in the reactive context, so signals read inside it drive the query.
361β
362#### options?
363β
364[`InjectInfiniteQueryOptions`](../interfaces/InjectInfiniteQueryOptions.md)
365β
366Additional configuration.
367β
368### Returns
369β
370[`CreateInfiniteQueryResult`](../type-aliases/CreateInfiniteQueryResult.md)\<`TData`, `TError`\>
371β
372The infinite query result.
373β
374<a id="parameters-summary"></a>
375β
376## Parameters
377β
378### injectInfiniteQueryFn
379β
380() => [`CreateInfiniteQueryOptions`](../interfaces/CreateInfiniteQueryOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`, `TPageParam`\>
381β
382A function that returns infinite query options. Similar to `computed` from
383Angular, this function runs in the reactive context, so signals read inside it drive the query.
384β
385<a id="injectInfiniteQueryFn-properties"></a>
386β
387#### `injectInfiniteQueryFn` properties
388β
389| Property | Type | Default value | Description |
390| ------ | ------ | ------ | ------ |
391| <a id="injectInfiniteQueryFn-property-enabled"></a> `enabled?` | \| `false` \| `true` \| ((`query`: [`Query`](../classes/Query.md)\<`TQueryFnData`, `TError`, [`InfiniteData`](../interfaces/InfiniteData.md)\<`TQueryFnData`, `TPageParam`\>, `TQueryKey`\>) => `boolean`) | `true` | Set this to `false` or a function that returns `false` to disable automatic refetching when the query mounts or changes query keys. To refetch the query, use the `refetch` method returned from the `useQuery` instance. Accepts a boolean or function that returns a boolean. |
392| <a id="injectInfiniteQueryFn-property-gctime"></a> `gcTime?` | `number` | `undefined` | The time in milliseconds that unused/inactive cache data remains in memory. When a query's cache becomes unused or inactive, that cache data will be garbage collected after this duration. When different garbage collection times are specified, the longest one will be used. Setting it to `Infinity` will disable garbage collection. Defaults to `5 * 60 * 1000` (5 minutes), or `Infinity` during SSR. Note: the maximum allowed time is about 24 days, imposed by `setTimeout`'s 32-bit signed integer delay β see `timeoutManager.setTimeoutProvider` for a workaround. |
393| <a id="injectInfiniteQueryFn-property-getnextpageparam"></a> `getNextPageParam` | (`lastPage`: `TQueryFnData`, `allPages`: `TQueryFnData`[], `lastPageParam`: `TPageParam`, `allPageParams`: `TPageParam`[]) => `TPageParam` \| `null` \| `undefined` | `undefined` | This function can be set to automatically get the next cursor for infinite queries. The result will also be used to determine the value of `hasNextPage`. |
394| <a id="injectInfiniteQueryFn-property-getpreviouspageparam"></a> `getPreviousPageParam?` | (`firstPage`: `TQueryFnData`, `allPages`: `TQueryFnData`[], `firstPageParam`: `TPageParam`, `allPageParams`: `TPageParam`[]) => `TPageParam` \| `null` \| `undefined` | `undefined` | This function can be set to automatically get the previous cursor for infinite queries. The result will also be used to determine the value of `hasPreviousPage`. |
395| <a id="injectInfiniteQueryFn-property-initialdata"></a> `initialData?` | \| [`InfiniteData`](../interfaces/InfiniteData.md)\<`TQueryFnData`, `TPageParam`\> \| (() => \| [`InfiniteData`](../interfaces/InfiniteData.md)\<`TQueryFnData`, `TPageParam`\> \| `undefined`) | `undefined` | If set, this value will be used as the initial data for the query cache (as long as the query hasn't been created or cached yet). If set to a function, the function will be called **once** during the shared/root query initialization, and be expected to synchronously return the initial data. Initial data is considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the cache. |
396| <a id="injectInfiniteQueryFn-property-initialdataupdatedat"></a> `initialDataUpdatedAt?` | `number` \| (() => `number` \| `undefined`) | `undefined` | If set, this value will be used as the time (in milliseconds) of when the `initialData` itself was last updated. |
397| <a id="injectInfiniteQueryFn-property-initialpageparam"></a> `initialPageParam` | `TPageParam` | `undefined` | The page param to start from when an infinite query has no pages yet. It is passed to `queryFn` as `pageParam` for the first page; every page after that gets the value returned by `getNextPageParam` or `getPreviousPageParam`. It only applies while the query has no pages: once a first page exists, refetching starts from that page's own param instead. |
398| <a id="injectInfiniteQueryFn-property-maxpages"></a> `maxPages?` | `number` | `undefined` | Maximum number of pages to store in the data of an infinite query. |
399| <a id="injectInfiniteQueryFn-property-meta"></a> `meta?` | `Record`\<`string`, `unknown`\> | `undefined` | Additional payload to be stored on each query. Use this property to pass information that can be used in other places. |
400| <a id="injectInfiniteQueryFn-property-networkmode"></a> `networkMode?` | `"online"` \| `"always"` \| `"offlineFirst"` | `'online'` | Controls whether a query is allowed to run based on the current network connectivity. **See** [Network Mode](https://tanstack.com/query/latest/docs/framework/react/guides/network-mode) for more information. |
401| <a id="injectInfiniteQueryFn-property-notifyonchangeprops"></a> `notifyOnChangeProps?` | \| ( \| `"error"` \| `"data"` \| `"isError"` \| `"isPending"` \| `"isLoading"` \| `"isLoadingError"` \| `"isRefetchError"` \| `"isSuccess"` \| `"isPlaceholderData"` \| `"status"` \| `"dataUpdatedAt"` \| `"errorUpdatedAt"` \| `"failureCount"` \| `"failureReason"` \| `"errorUpdateCount"` \| `"isFetched"` \| `"isFetchedAfterMount"` \| `"isFetching"` \| `"isInitialLoading"` \| `"isPaused"` \| `"isRefetching"` \| `"isStale"` \| `"isEnabled"` \| `"refetch"` \| `"fetchStatus"` \| `"fetchNextPage"` \| `"fetchPreviousPage"` \| `"hasNextPage"` \| `"hasPreviousPage"` \| `"isFetchNextPageError"` \| `"isFetchingNextPage"` \| `"isFetchPreviousPageError"` \| `"isFetchingPreviousPage"`)[] \| `"all"` \| (() => \| `"all"` \| ( \| `"error"` \| `"data"` \| `"isError"` \| `"isPending"` \| `"isLoading"` \| `"isLoadingError"` \| `"isRefetchError"` \| `"isSuccess"` \| `"isPlaceholderData"` \| `"status"` \| `"dataUpdatedAt"` \| `"errorUpdatedAt"` \| `"failureCount"` \| `"failureReason"` \| `"errorUpdateCount"` \| `"isFetched"` \| `"isFetchedAfterMount"` \| `"isFetching"` \| `"isInitialLoading"` \| `"isPaused"` \| `"isRefetching"` \| `"isStale"` \| `"isEnabled"` \| `"refetch"` \| `"fetchStatus"` \| `"fetchNextPage"` \| `"fetchPreviousPage"` \| `"hasNextPage"` \| `"hasPreviousPage"` \| `"isFetchNextPageError"` \| `"isFetchingNextPage"` \| `"isFetchPreviousPageError"` \| `"isFetchingPreviousPage"`)[] \| `undefined`) | `undefined` | If set, the component will only re-render if any of the listed properties change. When set to `['data', 'error']`, the component will only re-render when the `data` or `error` properties change. When set to `'all'`, the component will re-render whenever a query is updated. When set to a function, the function will be executed to compute the list of properties. Defaults to `undefined`, in which case property access is tracked automatically, and the component only re-renders when one of the tracked properties changes. |
402| <a id="injectInfiniteQueryFn-property-persister"></a> `persister?` | (`queryFn`: (`context`: [`QueryFunctionContext`](../type-aliases/QueryFunctionContext.md)\<`NoInfer`\<`TQueryKey`\>, `TPageParam`\>) => `TQueryFnData` \| `Promise`\<`TQueryFnData`\>, `context`: `object`, `query`: [`Query`](../classes/Query.md)) => `TQueryFnData` \| `Promise`\<`TQueryFnData`\> | `undefined` | This option can be used to persist the result of a query to an external storage, bypassing the need to actually call the `queryFn`. Useful for persisting a query's data across e.g. server/client boundaries. |
403| <a id="injectInfiniteQueryFn-property-placeholderdata"></a> `placeholderData?` | \| [`InfiniteData`](../interfaces/InfiniteData.md)\<`TQueryFnData`, `TPageParam`\> \| ((`previousData`: \| [`InfiniteData`](../interfaces/InfiniteData.md)\<`TQueryFnData`, `TPageParam`\> \| `undefined`, `previousQuery`: \| [`Query`](../classes/Query.md)\<[`InfiniteData`](../interfaces/InfiniteData.md)\<`TQueryFnData`, `TPageParam`\>, `TError`, [`InfiniteData`](../interfaces/InfiniteData.md)\<`TQueryFnData`, `TPageParam`\>, `TQueryKey`\> \| `undefined`) => \| [`InfiniteData`](../interfaces/InfiniteData.md)\<`TQueryFnData`, `TPageParam`\> \| `undefined`) | `undefined` | If set, this value will be used as the placeholder data for this particular query observer while the query is still in the `loading` data and no initialData has been provided. |
404| <a id="injectInfiniteQueryFn-property-queryfn"></a> `queryFn?` | \| *typeof* [`skipToken`](../variables/skipToken.md) \| ((`context`: [`QueryFunctionContext`](../type-aliases/QueryFunctionContext.md)\<`TQueryKey`, `TPageParam`\>) => `TQueryFnData` \| `Promise`\<`TQueryFnData`\>) | `undefined` | The function that the query will use to request data. Required, unless a default query function has been set via `queryClient.setQueryDefaults` or `queryClient.setDefaultOptions`. Receives a [QueryFunctionContext](../type-aliases/QueryFunctionContext.md). Must return a promise that will either resolve data or throw an error. The data cannot be `undefined`. |
405| <a id="injectInfiniteQueryFn-property-queryhash"></a> `queryHash?` | `string` | `undefined` | The hashed form of `queryKey`, computed with `queryKeyHashFn` (or the default hashing function otherwise). Used as the actual cache key internally. |
406| <a id="injectInfiniteQueryFn-property-querykey"></a> `queryKey` | `TQueryKey` & `object` | `undefined` | The query key to use for this query. The query key will be hashed into a stable hash. See [Query Keys](https://tanstack.com/query/latest/docs/framework/react/guides/query-keys) for more information. The query will automatically update when this key changes (as long as `enabled` is not set to `false`). |
407| <a id="injectInfiniteQueryFn-property-querykeyhashfn"></a> `queryKeyHashFn?` | (`queryKey`: `TQueryKey`) => `string` | `undefined` | If specified, this function is used to hash the `queryKey` to a string. |
408| <a id="injectInfiniteQueryFn-property-refetchinterval"></a> `refetchInterval?` | \| `number` \| `false` \| ((`query`: [`Query`](../classes/Query.md)\<`TQueryFnData`, `TError`, [`InfiniteData`](../interfaces/InfiniteData.md)\<`TQueryFnData`, `TPageParam`\>, `TQueryKey`\>) => `number` \| `false` \| `undefined`) | `false` | If set to a number, the query will continuously refetch at this frequency in milliseconds. If set to a function, the function will be executed with the latest data and query to compute a frequency |
409| <a id="injectInfiniteQueryFn-property-refetchintervalinbackground"></a> `refetchIntervalInBackground?` | `boolean` | `false` | If set to `true`, the query will continue to refetch while their tab/window is in the background. |
410| <a id="injectInfiniteQueryFn-property-refetchonmount"></a> `refetchOnMount?` | \| `boolean` \| `"always"` \| ((`query`: [`Query`](../classes/Query.md)\<`TQueryFnData`, `TError`, [`InfiniteData`](../interfaces/InfiniteData.md)\<`TQueryFnData`, `TPageParam`\>, `TQueryKey`\>) => `boolean` \| `"always"`) | `true` | If set to `true`, the query will refetch on mount if the data is stale. If set to `false`, will disable additional instances of a query to trigger background refetch. If set to `'always'`, the query will always refetch on mount (except when `staleTime: 'static'` is used). If set to a function, the function will be executed with the latest data and query to compute the value |
411| <a id="injectInfiniteQueryFn-property-refetchonreconnect"></a> `refetchOnReconnect?` | \| `boolean` \| `"always"` \| ((`query`: [`Query`](../classes/Query.md)\<`TQueryFnData`, `TError`, [`InfiniteData`](../interfaces/InfiniteData.md)\<`TQueryFnData`, `TPageParam`\>, `TQueryKey`\>) => `boolean` \| `"always"`) | `undefined` | If set to `true`, the query will refetch on reconnect if the data is stale. If set to `false`, the query will not refetch on reconnect. If set to `'always'`, the query will always refetch on reconnect (except when `staleTime: 'static'` is used). If set to a function, the function will be executed with the latest data and query to compute the value. Defaults to `true` unless `networkMode` is `'always'`. |
412| <a id="injectInfiniteQueryFn-property-refetchonwindowfocus"></a> `refetchOnWindowFocus?` | \| `boolean` \| `"always"` \| ((`query`: [`Query`](../classes/Query.md)\<`TQueryFnData`, `TError`, [`InfiniteData`](../interfaces/InfiniteData.md)\<`TQueryFnData`, `TPageParam`\>, `TQueryKey`\>) => `boolean` \| `"always"`) | `true` | If set to `true`, the query will refetch on window focus if the data is stale. If set to `false`, the query will not refetch on window focus. If set to `'always'`, the query will always refetch on window focus (except when `staleTime: 'static'` is used). If set to a function, the function will be executed with the latest data and query to compute the value. |
413| <a id="injectInfiniteQueryFn-property-retry"></a> `retry?` | \| `number` \| `false` \| `true` \| ((`failureCount`: `number`, `error`: `TError`) => `boolean`) | `undefined` | If `false`, failed queries will not retry by default. If `true`, failed queries will retry infinitely. If set to an integer number, e.g. 3, failed queries will retry until the failed query count meets that number. If set to a function `(failureCount, error) => boolean` failed queries will retry until the function returns false. Defaults to `3` on the client and `0` on the server. |
414| <a id="injectInfiniteQueryFn-property-retrydelay"></a> `retryDelay?` | `number` \| ((`failureCount`: `number`, `error`: `TError`) => `number`) | `undefined` | This function receives a `retryAttempt` integer and the actual Error and returns the delay to apply before the next attempt in milliseconds. A function like `attempt => Math.min(attempt > 1 ? 2 ** attempt * 1000 : 1000, 30 * 1000)` applies exponential backoff. A function like `attempt => attempt * 1000` applies linear backoff. Defaults to a function that applies exponential backoff, capped at 30 seconds. |
415| <a id="injectInfiniteQueryFn-property-retryonmount"></a> `retryOnMount?` | \| `false` \| `true` \| ((`query`: [`Query`](../classes/Query.md)\<`TQueryFnData`, `TError`, [`InfiniteData`](../interfaces/InfiniteData.md)\<`TQueryFnData`, `TPageParam`\>, `TQueryKey`\>) => `boolean`) | `true` | If set to `false`, the query will not be retried on mount if it contains an error. If set to a function, the function will be executed with the query to compute the value. |
416| <a id="injectInfiniteQueryFn-property-select"></a> `select?` | (`data`: [`InfiniteData`](../interfaces/InfiniteData.md)) => `TData` | `undefined` | This option can be used to transform or select a part of the data returned by the query function. It affects the returned `data` value, but does not affect what gets stored in the query cache. The `select` function will only run if `data` changed, or if the reference to the `select` function itself changes. To optimize, memoize the function so its reference stays stable across calls. |
417| <a id="injectInfiniteQueryFn-property-staletime"></a> `staleTime?` | \| `number` \| `"static"` \| ((`query`: [`Query`](../classes/Query.md)\<`TQueryFnData`, `TError`, [`InfiniteData`](../interfaces/InfiniteData.md)\<`TQueryFnData`, `TPageParam`\>, `TQueryKey`\>) => `number` \| `"static"`) | `0` | The time in milliseconds after data is considered stale. If set to `Infinity`, the data will never be considered stale. If set to `'static'`, the data will never be considered stale. If set to a function, the function will be executed with the query to compute a `staleTime`. |
418| <a id="injectInfiniteQueryFn-property-structuralsharing"></a> `structuralSharing?` | `boolean` \| ((`oldData`: `unknown`, `newData`: `unknown`) => `unknown`) | `true` | Set this to `false` to disable structural sharing between query results. Set this to a function which accepts the old and new data and returns resolved data of the same type to implement custom structural sharing logic. |
419| <a id="injectInfiniteQueryFn-property-throwonerror"></a> `throwOnError?` | \| `false` \| `true` \| ((`error`: `TError`, `query`: [`Query`](../classes/Query.md)\<`TQueryFnData`, `TError`, [`InfiniteData`](../interfaces/InfiniteData.md)\<`TQueryFnData`, `TPageParam`\>, `TQueryKey`\>) => `boolean`) | `false` | Whether errors should be thrown instead of setting the `error` property. If set to `true` or `suspense` is `true`, all errors will be thrown to the error boundary. If set to `false` and `suspense` is `false`, errors are returned as state. If set to a function, it will be passed the error and the query, and it should return a boolean indicating whether to show the error in an error boundary (`true`) or return the error as state (`false`). |
420β
421### options?
422β
423[`InjectInfiniteQueryOptions`](../interfaces/InjectInfiniteQueryOptions.md)
424β
425Additional configuration.
426β
427<a id="options-properties"></a>
428β
429#### `options` properties
430β
431| Property | Type | Description |
432| ------ | ------ | ------ |
433| <a id="options-property-injector"></a> `injector?` | `Injector` | The `Injector` in which to create the infinite query. If this is not provided, the current injection context will be used instead (via `inject`). |
434β
435<a id="returns-summary"></a>
436β
437## Returns
438β
439[`CreateInfiniteQueryResult`](../type-aliases/CreateInfiniteQueryResult.md)\<`TData`, `TError`\>
440β
441The infinite query result.
442β
443<a id="result-properties"></a>
444β
445### Result properties
446β
447Built from [`BaseQueryNarrowing`](../interfaces/BaseQueryNarrowing.md#properties), [`InfiniteQueryObserverBaseResult`](../interfaces/InfiniteQueryObserverBaseResult.md#properties). See the type above for what it changes.