Skip to content

Commit e161e4d

Browse files
committed
Add useInfiniteQuery description
1 parent 8195b47 commit e161e4d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,22 @@ export type InfiniteQueryStateSelector<
890890
D extends InfiniteQueryDefinition<any, any, any, any, any>,
891891
> = (state: UseInfiniteQueryStateDefaultResult<D>) => R
892892

893+
/**
894+
* A React hook that automatically triggers fetches of data from an endpoint, 'subscribes' the component to the cached data, and 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. 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.
895+
*
896+
* 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.
897+
*
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.
899+
*
900+
* #### Features
901+
*
902+
* - Automatically triggers requests to retrieve data based on the hook argument and whether cached data exists by default
903+
* - 'Subscribes' the component to keep cached data in the store, and 'unsubscribes' when the component unmounts
904+
* - Caches multiple pages worth of responses, and provides methods to trigger more page fetches forwards and backwards
905+
* - Accepts polling/re-fetching options to trigger automatic re-fetches when the corresponding criteria is met
906+
* - Returns the latest request status and cached data from the Redux store
907+
* - Re-renders as the request status changes and data becomes available
908+
*/
893909
export type UseInfiniteQuery<
894910
D extends InfiniteQueryDefinition<any, any, any, any, any>,
895911
> = <R extends Record<string, any> = UseInfiniteQueryStateDefaultResult<D>>(

0 commit comments

Comments
 (0)