Skip to content

Commit c3da64a

Browse files
committed
Flesh out infinite query description
1 parent 1c8b56d commit c3da64a

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

docs/rtk-query/api/created-api/hooks.mdx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -434,15 +434,13 @@ selectFromResult: () => ({})
434434
### `useInfiniteQuery`
435435
436436
```ts title="Accessing a useQuery hook" no-transpile
437-
const useQueryResult = api.endpoints.getPosts.useInfiniteQuery(arg, options)
437+
const useQueryResult = api.endpoints.getManyPosts.useInfiniteQuery(arg, options)
438438
// or
439-
const useQueryResult = api.useGetPostsInfiniteQuery(arg, options)
439+
const useQueryResult = api.useGetManyPostsInfiniteQuery(arg, options)
440440
```
441441

442442
[summary](docblock://query/react/buildHooks.ts?token=UseInfiniteQuery)
443443

444-
As with normal query hooks, `skipToken` is a valid argument that will skip the query from executing.
445-
446444
#### `useInfiniteQuery` Signature
447445

448446
```ts no-transpile

packages/toolkit/src/query/react/buildHooks.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,16 @@ export type InfiniteQueryStateSelector<
895895
*
896896
* The query arg is used as a cache key. Changing the query arg will tell the hook to re-fetch the data if it does not exist in the cache already, and the hook will return the data for that query arg once it's available.
897897
*
898-
* This hook combines the functionality of both [`useInfiniteQueryState`](#useinfinitequerystate) and [`useQuerySubscription`](#useinfinitequerysubscription) together, and is intended to be used in the majority of situations.
898+
* The `data` field will be a `{pages: Data[], pageParams: PageParam[]}` structure containing all fetched page responses and the corresponding page param values for each page. You may use this to render individual pages, combine all pages into a single infinite list, or other display logic as needed.
899+
*
900+
* This hook combines the functionality of both [`useInfiniteQueryState`](#useinfinitequerystate) and [`useInfiniteQuerySubscription`](#useinfinitequerysubscription) together, and is intended to be used in the majority of situations.
901+
*
902+
* As with normal query hooks, `skipToken` is a valid argument that will skip the query from executing.
903+
*
904+
* By default, the initial request will use the `initialPageParam` value that was defined on the infinite query endpoint. If you want to start from a different value, you can pass `initialPageParam` as part of the hook options to override that initial request value.
905+
*
906+
* Use the returned `fetchNextPage` and `fetchPreviousPage` methods on the hook result object to trigger fetches forwards and backwards. These will always calculate the next or previous page param based on the current cached pages and the provided `getNext/PreviousPageParam` callbacks defined in the endpoint.
907+
*
899908
*
900909
* #### Features
901910
*

0 commit comments

Comments
 (0)