Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions docs/rtk-query/api/created-api/hooks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,43 @@ const useInfiniteQuerySubscriptionResult =

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

##### `useInfiniteQuerySubscription` Signature

```ts no-transpile
type UseInfiniteQuerySubscription = (
arg: any | SkipToken,
options?: UseInfiniteQuerySubscriptionOptions,
) => UseInfiniteQuerySubscriptionResult

type UseInfiniteQuerySubscriptionOptions = {
skip?: boolean
refetchOnMountOrArgChange?: boolean | number
pollingInterval?: number
skipPollingIfUnfocused?: boolean
refetchOnReconnect?: boolean
refetchOnFocus?: boolean
initialPageParam?: PageParam
refetchCachedPages?: boolean
}

type UseInfiniteQuerySubscriptionResult = {
trigger: (arg: any, direction: 'forward' | 'backward') => InfiniteQueryActionCreatorResult
refetch: (options?: { refetchCachedPages?: boolean }) => InfiniteQueryActionCreatorResult
fetchNextPage: () => InfiniteQueryActionCreatorResult
fetchPreviousPage: () => InfiniteQueryActionCreatorResult
}
```

- **Parameters**
- `arg`: The query argument passed to the infinite query endpoint.
- `options`: A set of options that control the fetching behavior of the hook.
- **Returns**
- An object containing:
- `trigger`: manually fetches a page in the given direction for the current cache entry
- `refetch`: refetches the infinite query
- `fetchNextPage`: fetches the next page
- `fetchPreviousPage`: fetches the previous page

### `useLazyQuerySubscription`

```ts title="Accessing a useLazyQuerySubscription hook" no-transpile
Expand Down
10 changes: 5 additions & 5 deletions packages/toolkit/src/query/react/buildHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -798,19 +798,19 @@ export type LazyInfiniteQueryTrigger<
D extends InfiniteQueryDefinition<any, any, any, any, any>,
> = {
/**
* Triggers a lazy query.
* Triggers an infinite query fetch in the given direction.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Triggers an infinite query fetch in the given direction.
* Triggers fetching the next or previous page of an infinite query.

*
* By default, this will start a new request even if there is already a value in the cache.
* If you want to use the cache value and only start a request if there is no cache value, set the second argument to `true`.
* Pass the endpoint argument as the first parameter and either `'forward'` or `'backward'`
* as the second parameter to fetch the next or previous page from the current cache entry.
*
* @remarks
* If you need to access the error or success payload immediately after a lazy query, you can chain .unwrap().
* If you need to access the error or success payload immediately after triggering the request, you can chain `.unwrap()`.
Comment on lines +803 to +807

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Pass the endpoint argument as the first parameter and either `'forward'` or `'backward'`
* as the second parameter to fetch the next or previous page from the current cache entry.
*
* @remarks
* If you need to access the error or success payload immediately after a lazy query, you can chain .unwrap().
* If you need to access the error or success payload immediately after triggering the request, you can chain `.unwrap()`.
* @param arg - The query argument identifying the infinite query cache entry.
* @param direction - The {@linkcode InfiniteQueryDirection | direction} to fetch: **`'forward'`** fetches the next page, and **`'backward'`** fetches the previous page.
* @returns A {@linkcode InfiniteQueryActionCreatorResult | promise-like result object} for the triggered request. Chain {@linkcode InfiniteQueryActionCreatorResult.unwrap | .unwrap()} to access the fulfilled payload or throw the rejected error.

*
* @example
* ```ts
* // codeblock-meta title="Using .unwrap with async await"
* try {
* const payload = await getUserById(1).unwrap();
* const payload = await triggerPosts('fire', 'forward').unwrap();
* console.log('fulfilled', payload);
* } catch (error) {
* console.error('rejected', error);
Expand Down
Loading