Skip to content

Commit

Permalink
Require initialPageParam value
Browse files Browse the repository at this point in the history
  • Loading branch information
markerikson committed Oct 24, 2024
1 parent 0ed9cd2 commit 2c39bf3
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/toolkit/src/query/core/apiState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export type GetPreviousPageParamFunction<TPageParam, TQueryFnData> = (
) => TPageParam | undefined | null

export type InfiniteQueryConfigOptions<TQueryFnData, TPageParam> = {
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`.
Expand Down
3 changes: 2 additions & 1 deletion packages/toolkit/src/query/core/buildThunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/toolkit/src/query/endpointDefinitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ export interface InfiniteQueryExtraOptions<
*/
invalidatesTags?: never

infiniteQueryOptions: InfiniteQueryConfigOptions<ResultType, QueryArg>
infiniteQueryOptions: InfiniteQueryConfigOptions<ResultType, PageParam>

/**
* Can be provided to return a custom cache key value based on the query arguments.
Expand Down
1 change: 1 addition & 0 deletions packages/toolkit/src/query/react/buildHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1943,6 +1943,7 @@ export function buildHooks<Definitions extends EndpointDefinitions>({
const queryStateResults = useInfiniteQueryState(
arg,
{
initialPageParam: options?.initialPageParam!,
getNextPageParam: options?.getNextPageParam!,
getPreviousPageParam: options?.getPreviousPageParam,
},
Expand Down
2 changes: 2 additions & 0 deletions packages/toolkit/src/query/tests/buildHooks.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,7 @@ describe('hooks tests', () => {
endpoints: (builder) => ({
getInfinitePokemon: builder.infiniteQuery<any, string, number>({
infiniteQueryOptions: {
initialPageParam: 0,
getNextPageParam: (
lastPage,
allPages,
Expand Down Expand Up @@ -813,6 +814,7 @@ describe('hooks tests', () => {
function User() {
const { data, isFetching, isUninitialized, fetchNextPage } =
pokemonApi.endpoints.getInfinitePokemon.useInfiniteQuery('a', {

Check failure on line 816 in packages/toolkit/src/query/tests/buildHooks.test.tsx

View workflow job for this annotation

GitHub Actions / Test against dist (20.x)

Unhandled error

TypeCheckError: Argument of type '"a"' is not assignable to parameter of type 'unique symbol'. ❯ src/query/tests/buildHooks.test.tsx:816:68
initialPageParam: 0,
getNextPageParam: (lastPageParam) => lastPageParam + 1,
})

Expand Down

0 comments on commit 2c39bf3

Please sign in to comment.