Skip to content

Commit

Permalink
Fix infiniteQueryOptions example compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
markerikson committed Jan 20, 2025
1 parent f5aaa4f commit 46c922a
Showing 1 changed file with 30 additions and 25 deletions.
55 changes: 30 additions & 25 deletions packages/toolkit/src/query/endpointDefinitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -618,33 +618,38 @@ export interface InfiniteQueryExtraOptions<
*
* ```ts
* // codeblock-meta title="infiniteQueryOptions example"
* getInfinitePokemonWithMax: build.infiniteQuery<
Pokemon[],
string,
number
>({
infiniteQueryOptions: {
initialPageParam: 0,
maxPages: 3,
getNextPageParam: (
lastPage,
allPages,
lastPageParam,
allPageParams,
) => lastPageParam + 1,
getPreviousPageParam: (
firstPage,
allPages,
firstPageParam,
allPageParams,
) => {
return firstPageParam > 0 ? firstPageParam - 1 : undefined
* import { createApi, fetchBaseQuery, defaultSerializeQueryArgs } from '@reduxjs/toolkit/query/react'
*
* type Pokemon = {
* id: string
* name: string
* }
*
const pokemonApi = createApi({
baseQuery: fetchBaseQuery({ baseUrl: 'https://pokeapi.co/api/v2/' }),
endpoints: (build) => ({
getInfinitePokemonWithMax: build.infiniteQuery<Pokemon[], string, number>({
infiniteQueryOptions: {
initialPageParam: 0,
maxPages: 3,
getNextPageParam: (lastPage, allPages, lastPageParam, allPageParams) =>
lastPageParam + 1,
getPreviousPageParam: (
firstPage,
allPages,
firstPageParam,
allPageParams,
) => {
return firstPageParam > 0 ? firstPageParam - 1 : undefined
},
},
query(pageParam) {
return `https://example.com/listItems?page=${pageParam}`
},
},
query(pageParam) {
return `https://example.com/listItems?page=${pageParam}`
},
}),
}),
})
* ```
*/
infiniteQueryOptions: InfiniteQueryConfigOptions<ResultType, PageParam>
Expand Down

0 comments on commit 46c922a

Please sign in to comment.