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

injectInfiniteQuery.md

415 lines26.5 KB

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>(optionsFn: () => DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): DefinedCreateInfiniteQueryResult<TData, TError>;
12function injectInfiniteQuery<TQueryFnData, TError = Error, TData = InfiniteData<TQueryFnData, unknown>, TQueryKey extends readonly unknown[] = readonly unknown[], TPageParam = unknown>(optionsFn: () => UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): CreateInfiniteQueryResult<TData, TError>;
13function injectInfiniteQuery<TQueryFnData, TError = Error, TData = InfiniteData<TQueryFnData, unknown>, TQueryKey extends readonly unknown[] = readonly unknown[], TPageParam = unknown>(optionsFn: () => CreateInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): 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>(optionsFn: () => DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): DefinedCreateInfiniteQueryResult<TData, TError>;
28```
29​
30Defined in: [packages/angular-query/src/inject-infinite-query.ts:77](https://github.com/TanStack/query/blob/main/packages/angular-query/src/inject-infinite-query.ts#L77)
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 known to be defined on the options returned by
37`optionsFn`, so the resulting `data` signal is never `undefined` (unless a `select` changes
38`TData` to include `undefined`).
39​
40### Type Parameters
41​
42#### TQueryFnData
43​
44`TQueryFnData`
45​
46#### TError
47​
48`TError` = `Error`
49​
50#### TData
51​
52`TData` = [`InfiniteData`](../interfaces/InfiniteData.md)\<`TQueryFnData`, `unknown`\>
53​
54#### TQueryKey
55​
56`TQueryKey` *extends* readonly `unknown`[] = readonly `unknown`[]
57​
58#### TPageParam
59​
60`TPageParam` = `unknown`
61​
62### Parameters
63​
64#### optionsFn
65​
66() => [`DefinedInitialDataInfiniteOptions`](../type-aliases/DefinedInitialDataInfiniteOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`, `TPageParam`\>
67​
68A function returning the [DefinedInitialDataInfiniteOptions](../type-aliases/DefinedInitialDataInfiniteOptions.md) to use β€”
69everything you can pass to `injectInfiniteQuery`, with `initialData` known to be defined. Similar to
70`computed` from Angular, this function runs in the reactive context, so signals read inside it drive the
71query.
72​
73### Returns
74​
75[`DefinedCreateInfiniteQueryResult`](../type-aliases/DefinedCreateInfiniteQueryResult.md)\<`TData`, `TError`\>
76​
77The same signals as `injectQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,
78`hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data().pages` and
79`data().pageParams` are also added, as long as a `select` doesn't change `TData` away from its default
80`InfiniteData<TQueryFnData>` shape.
81​
82### Remarks
83​
84Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default
85refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user
86actions, or add conditions like `hasNextPage() && !isFetching()`.
87​
88### See
89​
90 - https://tanstack.com/query/latest/docs/framework/angular/guides/infinite-queries
91 - [infiniteQueryOptions](infiniteQueryOptions.md) to share these options between `injectInfiniteQuery` and imperative APIs
92like `queryClient.infiniteQuery`.
93​
94### Example
95​
96```angular-ts
97@Component({
98 selector: 'projects',
99 template: `
100 <!-- projectsQuery.data() is never undefined, thanks to initialData β€” even if a
101 refetch fails, so the list stays visible alongside the error. -->
102 <ul>
103 @for (page of projectsQuery.data().pages; track $index) {
104 @for (project of page.projects; track project.id) {
105 <li>{{ project.name }}</li>
106 }
107 }
108 </ul>
109 `,
110})
111export class Projects {
112 readonly projectsQuery = injectInfiniteQuery(() => ({
113 queryKey: ['projects'],
114 queryFn: ({ pageParam }) => fetchProjects(pageParam),
115 initialPageParam: 0,
116 getNextPageParam: (lastPage) => lastPage.nextId,
117 initialData: { pages: [], pageParams: [] },
118 }))
120```
121​
122<a id="call-signature-2"></a>
123​
124## Call Signature
125​
126```ts
127function injectInfiniteQuery<TQueryFnData, TError = Error, TData = InfiniteData<TQueryFnData, unknown>, TQueryKey extends readonly unknown[] = readonly unknown[], TPageParam = unknown>(optionsFn: () => UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): CreateInfiniteQueryResult<TData, TError>;
128```
129​
130Defined in: [packages/angular-query/src/inject-infinite-query.ts:228](https://github.com/TanStack/query/blob/main/packages/angular-query/src/inject-infinite-query.ts#L228)
131​
132Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a
133unique key. Infinite queries can additively "load more" data onto an existing set of data, or
134"infinite scroll".
135​
136### Type Parameters
137​
138#### TQueryFnData
139​
140`TQueryFnData`
141​
142#### TError
143​
144`TError` = `Error`
145​
146#### TData
147​
148`TData` = [`InfiniteData`](../interfaces/InfiniteData.md)\<`TQueryFnData`, `unknown`\>
149​
150#### TQueryKey
151​
152`TQueryKey` *extends* readonly `unknown`[] = readonly `unknown`[]
153​
154#### TPageParam
155​
156`TPageParam` = `unknown`
157​
158### Parameters
159​
160#### optionsFn
161​
162() => [`UndefinedInitialDataInfiniteOptions`](../type-aliases/UndefinedInitialDataInfiniteOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`, `TPageParam`\>
163​
164A function returning the [UndefinedInitialDataInfiniteOptions](../type-aliases/UndefinedInitialDataInfiniteOptions.md) to use
165β€” everything you can pass to `injectInfiniteQuery`. Similar to `computed` from Angular, this function runs
166in the reactive context, so signals read inside it drive the query.
167​
168### Returns
169​
170[`CreateInfiniteQueryResult`](../type-aliases/CreateInfiniteQueryResult.md)\<`TData`, `TError`\>
171​
172The same signals as `injectQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,
173`hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data().pages` and
174`data().pageParams` are also added, as long as a `select` doesn't change `TData` away from its default
175`InfiniteData<TQueryFnData>` shape.
176​
177### Remarks
178​
179Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default
180refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user
181actions, or add conditions like `hasNextPage() && !isFetching()`. `queryFn: skipToken` is also accepted,
182shown below.
183​
184### See
185​
186 - https://tanstack.com/query/latest/docs/framework/angular/guides/infinite-queries
187 - [infiniteQueryOptions](infiniteQueryOptions.md) to share these options between `injectInfiniteQuery` and imperative APIs
188like `queryClient.infiniteQuery`.
189​
190### Examples
191​
192Fetching the next page from a button click:
193```angular-ts
194@Component({
195 selector: 'projects-list',
196 template: `
197 <ul>
198 @for (page of projectsQuery.data()?.pages; track $index) {
199 @for (project of page.projects; track project.id) {
200 <li>{{ project.name }}</li>
201 }
202 }
203 </ul>
204 <button
205 [disabled]="!projectsQuery.hasNextPage() || projectsQuery.isFetching()"
206 (click)="projectsQuery.fetchNextPage()"
207 >
208 Load More
209 </button>
210 `,
211})
212export class ProjectsList {
213 readonly projectsQuery = injectInfiniteQuery(() => ({
214 queryKey: ['projects'],
215 queryFn: ({ pageParam }) => fetchProjects(pageParam),
216 initialPageParam: 0,
217 getNextPageParam: (lastPage) => lastPage.nextId,
218 }))
220```
221​
222Fetching the next page automatically as the user scrolls, using an `IntersectionObserver` on a sentinel
223element after the list:
224```angular-ts
225@Component({
226 selector: 'projects-list',
227 template: `
228 <ul>
229 @for (page of projectsQuery.data()?.pages; track $index) {
230 @for (project of page.projects; track project.id) {
231 <li>{{ project.name }}</li>
232 }
233 }
234 </ul>
235 <div #sentinel>{{ projectsQuery.isFetchingNextPage() ? 'Loading more...' : '' }}</div>
236 `,
237})
238export class ProjectsList {
239 readonly sentinel = viewChild<ElementRef<HTMLElement>>('sentinel')
240​
241 readonly projectsQuery = injectInfiniteQuery(() => ({
242 queryKey: ['projects'],
243 queryFn: ({ pageParam }) => fetchProjects(pageParam),
244 initialPageParam: 0,
245 getNextPageParam: (lastPage) => lastPage.nextId,
246 }))
247​
248 constructor() {
249 effect((onCleanup) => {
250 const sentinel = this.sentinel()?.nativeElement
251 if (
252 sentinel == null ||
253 !this.projectsQuery.hasNextPage() ||
254 this.projectsQuery.isFetching()
255 ) {
256 return
257 }
258​
259 const observer = new IntersectionObserver(([entry]) => {
260 if (entry?.isIntersecting) this.projectsQuery.fetchNextPage()
261 })
262 observer.observe(sentinel)
263​
264 onCleanup(() => observer.disconnect())
265 })
266 }
268```
269​
270A query that's disabled, type safe, until `postId` is set β€” pass `skipToken` as `queryFn` instead of
271setting `enabled: false`:
272```angular-ts
273@Component({
274 selector: 'comments',
275 template: `
276 @if (postId() == null) {
277 Select a post
278 } @else if (commentsQuery.isPending()) {
279 Loading...
280 } @else if (commentsQuery.isError()) {
281 <span>Error: {{ commentsQuery.error()?.message }}</span>
282 } @else {
283 <ul>
284 @for (page of commentsQuery.data().pages; track $index) {
285 @for (comment of page.comments; track comment.id) {
286 <li>{{ comment.text }}</li>
287 }
288 }
289 </ul>
290 }
291 `,
292})
293export class Comments {
294 readonly postId = signal<string | undefined>(undefined)
295​
296 readonly commentsQuery = injectInfiniteQuery(() => ({
297 queryKey: ['post', this.postId(), 'comments'],
298 queryFn:
299 this.postId() != null
300 ? ({ pageParam }) => fetchComments(this.postId()!, pageParam)
301 : skipToken,
302 initialPageParam: 0,
303 getNextPageParam: (lastPage) => lastPage.nextId,
304 }))
306```
307​
308<a id="call-signature-3"></a>
309​
310## Call Signature
311​
312```ts
313function injectInfiniteQuery<TQueryFnData, TError = Error, TData = InfiniteData<TQueryFnData, unknown>, TQueryKey extends readonly unknown[] = readonly unknown[], TPageParam = unknown>(optionsFn: () => CreateInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): CreateInfiniteQueryResult<TData, TError>;
314```
315​
316Defined in: [packages/angular-query/src/inject-infinite-query.ts:254](https://github.com/TanStack/query/blob/main/packages/angular-query/src/inject-infinite-query.ts#L254)
317​
318This overload accepts the general [CreateInfiniteQueryOptions](../interfaces/CreateInfiniteQueryOptions.md) shape rather than the
319`initialData`-aware overloads above, so whether `data` is defined can't be inferred from the call site β€”
320useful when wrapping `injectInfiniteQuery` in your own helper function that forwards caller-provided
321options.
322​
323### Type Parameters
324​
325#### TQueryFnData
326​
327`TQueryFnData`
328​
329#### TError
330​
331`TError` = `Error`
332​
333#### TData
334​
335`TData` = [`InfiniteData`](../interfaces/InfiniteData.md)\<`TQueryFnData`, `unknown`\>
336​
337#### TQueryKey
338​
339`TQueryKey` *extends* readonly `unknown`[] = readonly `unknown`[]
340​
341#### TPageParam
342​
343`TPageParam` = `unknown`
344​
345### Parameters
346​
347#### optionsFn
348​
349() => [`CreateInfiniteQueryOptions`](../interfaces/CreateInfiniteQueryOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`, `TPageParam`\>
350​
351A function that returns infinite query options. Similar to `computed` from
352Angular, this function runs in the reactive context, so signals read inside it drive the query.
353​
354### Returns
355​
356[`CreateInfiniteQueryResult`](../type-aliases/CreateInfiniteQueryResult.md)\<`TData`, `TError`\>
357​
358The infinite query result.
359​
360### See
361​
362https://tanstack.com/query/latest/docs/framework/angular/guides/infinite-queries
363​
364<a id="parameters-summary"></a>
365​
366## Parameters
367​
368### optionsFn
369​
370() => [`CreateInfiniteQueryOptions`](../interfaces/CreateInfiniteQueryOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`, `TPageParam`\>
371​
372A function that returns infinite query options. Similar to `computed` from
373Angular, this function runs in the reactive context, so signals read inside it drive the query.
374​
375<a id="optionsFn-properties"></a>
376​
377#### `optionsFn` properties
378​
379| Property | Type | Default value | Description |
380| ------ | ------ | ------ | ------ |
381| <a id="optionsFn-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. |
382| <a id="optionsFn-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. |
383| <a id="optionsFn-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`. |
384| <a id="optionsFn-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`. |
385| <a id="optionsFn-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. |
386| <a id="optionsFn-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. |
387| <a id="optionsFn-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. |
388| <a id="optionsFn-property-maxpages"></a> `maxPages?` | `number` | `undefined` | Maximum number of pages to store in the data of an infinite query. |
389| <a id="optionsFn-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. |
390| <a id="optionsFn-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. |
391| <a id="optionsFn-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. |
392| <a id="optionsFn-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. |
393| <a id="optionsFn-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`. |
394| <a id="optionsFn-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. |
395| <a id="optionsFn-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`). |
396| <a id="optionsFn-property-querykeyhashfn"></a> `queryKeyHashFn?` | (`queryKey`: `TQueryKey`) => `string` | `undefined` | If specified, this function is used to hash the `queryKey` to a string. |
397| <a id="optionsFn-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 |
398| <a id="optionsFn-property-refetchintervalinbackground"></a> `refetchIntervalInBackground?` | `boolean` | `false` | If set to `true`, the query will continue to refetch while their tab/window is in the background. |
399| <a id="optionsFn-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 |
400| <a id="optionsFn-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'`. |
401| <a id="optionsFn-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. |
402| <a id="optionsFn-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. |
403| <a id="optionsFn-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. |
404| <a id="optionsFn-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. |
405| <a id="optionsFn-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. |
406| <a id="optionsFn-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`. |
407| <a id="optionsFn-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. |
408​
409<a id="returns-summary"></a>
410​
411## Returns
412​
413[`CreateInfiniteQueryResult`](../type-aliases/CreateInfiniteQueryResult.md)\<`TData`, `TError`\>
414​
415The infinite query result.