Skip to content

Commit 1c8b56d

Browse files
committed
Add infinite state/subscription descriptions
1 parent e161e4d commit 1c8b56d

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,8 +785,22 @@ type UseQuerySubscriptionResult = {
785785
786786
### `useInfiniteQueryState`
787787
788+
```ts title="Accessing a useInfiniteQueryState hook" no-transpile
789+
const useInfiniteQueryStateResult =
790+
api.endpoints.getManyPosts.useInfiniteQueryState(arg, options)
791+
```
792+
793+
[summary](docblock://query/react/buildHooks.ts?token=UseInfiniteQueryState)
794+
788795
### `useInfiniteQuerySubscription`
789796

797+
```ts title="Accessing a useInfiniteQuerySubscription hook" no-transpile
798+
const useInfiniteQuerySubscriptionResult =
799+
api.endpoints.getManyPosts.useInfiniteQuerySubscription(arg, options)
800+
```
801+
802+
[summary](docblock://query/react/buildHooks.ts?token=UseInfiniteQuerySubscription)
803+
790804
### `useLazyQuerySubscription`
791805

792806
```ts title="Accessing a useLazyQuerySubscription hook" no-transpile

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,16 @@ export type UseInfiniteQuery<
918918
'fetchNextPage' | 'fetchPreviousPage'
919919
>
920920

921+
/**
922+
* A React hook that reads the request status and cached data from the Redux store. The component will re-render as the loading status changes and the data becomes available.
923+
*
924+
* Note that this hook does not trigger fetching new data. For that use-case, see [`useInfiniteQuery`](#useinfinitequery) or [`useInfiniteQuerySubscription`](#useinfinitequerysubscription).
925+
*
926+
* #### Features
927+
*
928+
* - Returns the latest request status and cached data from the Redux store
929+
* - Re-renders as the request status changes and data becomes available
930+
*/
921931
export type UseInfiniteQueryState<
922932
D extends InfiniteQueryDefinition<any, any, any, any, any>,
923933
> = <R extends Record<string, any> = UseInfiniteQueryStateDefaultResult<D>>(
@@ -941,6 +951,20 @@ export type TypedUseInfiniteQueryState<
941951
>
942952
>
943953

954+
/**
955+
* A React hook that automatically triggers fetches of data from an endpoint, and 'subscribes' the component to the cached data. Additionally, it will cache multiple "pages" worth of responses within a single cache entry, and allows fetching more pages forwards and backwards from the current cached pages.
956+
*
957+
* 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.
958+
*
959+
* Note that this hook does not return a request status or cached data. For that use-case, see [`useInfiniteQuery`](#useinfinitequery) or [`useInfiniteQueryState`](#useinfinitequerystate).
960+
*
961+
* #### Features
962+
*
963+
* - Automatically triggers requests to retrieve data based on the hook argument and whether cached data exists by default
964+
* - 'Subscribes' the component to keep cached data in the store, and 'unsubscribes' when the component unmounts
965+
* - Caches multiple pages worth of responses, and provides methods to trigger more page fetches forwards and backwards
966+
* - Accepts polling/re-fetching options to trigger automatic re-fetches when the corresponding criteria is met
967+
*/
944968
export type UseInfiniteQuerySubscription<
945969
D extends InfiniteQueryDefinition<any, any, any, any, any>,
946970
> = (

0 commit comments

Comments
 (0)