From dfb1093e7d2361203bfbec0c369792e05de1444d Mon Sep 17 00:00:00 2001 From: Mark Erikson Date: Thu, 24 Oct 2024 16:06:42 +0100 Subject: [PATCH] Require initialPageParam value --- packages/toolkit/src/query/core/apiState.ts | 1 + packages/toolkit/src/query/core/buildThunks.ts | 3 ++- packages/toolkit/src/query/react/buildHooks.ts | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/toolkit/src/query/core/apiState.ts b/packages/toolkit/src/query/core/apiState.ts index 26647ce41f..ca9d2c1833 100644 --- a/packages/toolkit/src/query/core/apiState.ts +++ b/packages/toolkit/src/query/core/apiState.ts @@ -45,6 +45,7 @@ export type GetPreviousPageParamFunction = ( ) => TPageParam | undefined | null export type InfiniteQueryConfigOptions = { + initialPageParam: TPageParam /** * This function can be set to automatically get the previous cursor for infinite queries. * The result will also be used to determine the value of `hasPreviousPage`. diff --git a/packages/toolkit/src/query/core/buildThunks.ts b/packages/toolkit/src/query/core/buildThunks.ts index d775c3c9fc..6d3ac0a216 100644 --- a/packages/toolkit/src/query/core/buildThunks.ts +++ b/packages/toolkit/src/query/core/buildThunks.ts @@ -561,7 +561,8 @@ export function buildThunks< // Fetch first page result = await fetchPage( existingData, - existingData.pageParams[0] ?? arg.originalArgs, + existingData.pageParams[0] ?? + endpointDefinition.infiniteQueryOptions.initialPageParam, // arg.originalArgs, ) //original diff --git a/packages/toolkit/src/query/react/buildHooks.ts b/packages/toolkit/src/query/react/buildHooks.ts index befc6139c4..30ad40cc32 100644 --- a/packages/toolkit/src/query/react/buildHooks.ts +++ b/packages/toolkit/src/query/react/buildHooks.ts @@ -1943,6 +1943,7 @@ export function buildHooks({ const queryStateResults = useInfiniteQueryState( arg, { + initialPageParam: options?.initialPageParam!, getNextPageParam: options?.getNextPageParam!, getPreviousPageParam: options?.getPreviousPageParam, },