From 8f13f0b1fdb99eabf14aa033dde8be7f415ec3a4 Mon Sep 17 00:00:00 2001 From: lilianakatrina684-a11y Date: Sun, 22 Mar 2026 02:39:18 +0800 Subject: [PATCH] docs: fix LazyInfiniteQueryTrigger docs --- docs/rtk-query/api/created-api/hooks.mdx | 37 +++++++++++++++++++ .../toolkit/src/query/react/buildHooks.ts | 10 ++--- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/docs/rtk-query/api/created-api/hooks.mdx b/docs/rtk-query/api/created-api/hooks.mdx index 55db43d946..401da15de9 100644 --- a/docs/rtk-query/api/created-api/hooks.mdx +++ b/docs/rtk-query/api/created-api/hooks.mdx @@ -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 diff --git a/packages/toolkit/src/query/react/buildHooks.ts b/packages/toolkit/src/query/react/buildHooks.ts index 5c6bfe709f..864b8c31fe 100644 --- a/packages/toolkit/src/query/react/buildHooks.ts +++ b/packages/toolkit/src/query/react/buildHooks.ts @@ -798,19 +798,19 @@ export type LazyInfiniteQueryTrigger< D extends InfiniteQueryDefinition, > = { /** - * Triggers a lazy query. + * Triggers an infinite query fetch in the given direction. * - * 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()`. * * @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);