Skip to content

Commit 8f9a460

Browse files
committed
docs: ensureInfiniteQueryData
1 parent caa0d43 commit 8f9a460

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

docs/reference/QueryClient.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Its available methods are:
2929
- [`queryClient.prefetchInfiniteQuery`](#queryclientprefetchinfinitequery)
3030
- [`queryClient.getQueryData`](#queryclientgetquerydata)
3131
- [`queryClient.ensureQueryData`](#queryclientensurequerydata)
32+
- [`queryClient.ensureInfiniteQueryData`](#queryclientensureinfinitequerydata)
3233
- [`queryClient.getQueriesData`](#queryclientgetqueriesdata)
3334
- [`queryClient.setQueryData`](#queryclientsetquerydata)
3435
- [`queryClient.getQueryState`](#queryclientgetquerystate)
@@ -200,6 +201,31 @@ const data = await queryClient.ensureQueryData({ queryKey, queryFn })
200201

201202
- `Promise<TData>`
202203

204+
## `queryClient.ensureInfiniteQueryData`
205+
206+
`ensureInfiniteQueryData` is an asynchronous function that can be used to get an existing infinite query's cached data. If the query does not exist, `queryClient.fetchInfiniteQuery` will be called and its results returned.
207+
208+
```tsx
209+
const data = await queryClient.ensureInfiniteQueryData({
210+
queryKey,
211+
queryFn,
212+
initialPageParam,
213+
getNextPageParam,
214+
})
215+
```
216+
217+
**Options**
218+
219+
- the same options as [`fetchInfiniteQuery`](#queryclientfetchinfinitequery)
220+
- `revalidateIfStale: boolean`
221+
- Optional
222+
- Defaults to `false`
223+
- If set to `true`, stale data will be refetched in the background, but cached data will be returned immediately.
224+
225+
**Returns**
226+
227+
- `Promise<InfiniteData<TData, TPageParam>>`
228+
203229
## `queryClient.getQueriesData`
204230

205231
`getQueriesData` is a synchronous function that can be used to get the cached data of multiple queries. Only queries that match the passed queryKey or queryFilter will be returned. If there are no matching queries, an empty array will be returned.

0 commit comments

Comments
 (0)