Skip to content

Commit 3aa0680

Browse files
authored
refactor(infinite-queries): rename defaultPageParam to initialPageParam (#5888)
* refactor(query-core): rename defaultPageParam to initialPageParam Closes: #5885 * test(query-core): rename defaultPageParam to initialPageParam * test(react-query): rename defaultPageParam to initialPageParam * test(solid-query): rename defaultPageParam to initialPageParam * test(vue-query): rename defaultPageParam to initialPageParam * build(codemods): rename defaultPageParam to initialPageParam * docs(react-query, examples): rename defaultPageParam to initialPageParam * docs(react-query): rename defaultPageParam to initialPageParam * docs(svelte-query, examples): rename defaultPageParam to initialPageParam
1 parent 787efb5 commit 3aa0680

File tree

24 files changed

+107
-107
lines changed

24 files changed

+107
-107
lines changed

docs/react/guides/infinite-queries.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ When using `useInfiniteQuery`, you'll notice a few things are different:
1111
- `data.pages` array containing the fetched pages
1212
- `data.pageParams` array containing the page params used to fetch the pages
1313
- The `fetchNextPage` and `fetchPreviousPage` functions are now available (`fetchNextPage` is required)
14-
- The `defaultPageParam` option is now available (and required) to specify the initial page param
14+
- The `initialPageParam` option is now available (and required) to specify the initial page param
1515
- The `getNextPageParam` and `getPreviousPageParam` options are available for both determining if there is more data to load and the information to fetch it. This information is supplied as an additional parameter in the query function
1616
- A `hasNextPage` boolean is now available and is `true` if `getNextPageParam` returns a value other than `null` or `undefined`
1717
- A `hasPreviousPage` boolean is now available and is `true` if `getPreviousPageParam` returns a value other than `null` or `undefined`
@@ -62,7 +62,7 @@ function Projects() {
6262
} = useInfiniteQuery({
6363
queryKey: ['projects'],
6464
queryFn: fetchProjects,
65-
defaultPageParam: 0,
65+
initialPageParam: 0,
6666
getNextPageParam: (lastPage, pages) => lastPage.nextCursor,
6767
})
6868

@@ -113,7 +113,7 @@ Bi-directional lists can be implemented by using the `getPreviousPageParam`, `fe
113113
useInfiniteQuery({
114114
queryKey: ['projects'],
115115
queryFn: fetchProjects,
116-
defaultPageParam: 0,
116+
initialPageParam: 0,
117117
getNextPageParam: (lastPage, pages) => lastPage.nextCursor,
118118
getPreviousPageParam: (firstPage, pages) => firstPage.prevCursor,
119119
})
@@ -208,7 +208,7 @@ In the following example only 3 pages are kept in the query data pages array. If
208208
useInfiniteQuery({
209209
queryKey: ['projects'],
210210
queryFn: fetchProjects,
211-
defaultPageParam: 0,
211+
initialPageParam: 0,
212212
getNextPageParam: (lastPage, pages) => lastPage.nextCursor,
213213
getPreviousPageParam: (firstPage, pages) => firstPage.prevCursor,
214214
maxPages: 3,
@@ -225,7 +225,7 @@ If your API doesn't return a cursor, you can use the `pageParam` as a cursor. Be
225225
return useInfiniteQuery({
226226
queryKey: ['projects'],
227227
queryFn: fetchProjects,
228-
defaultPageParam: 0,
228+
initialPageParam: 0,
229229
getNextPageParam: (lastPage, allPages, lastPageParam) => {
230230
if (lastPage.length === 0) {
231231
return undefined

docs/react/guides/migrating-to-v5.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,18 +321,18 @@ The options you can pass to dehydrate have been simplified. Queries and Mutation
321321
- dehydrateQueries?: boolean
322322
```
323323

324-
### Infinite queries now need a `defaultPageParam`
324+
### Infinite queries now need a `initialPageParam`
325325

326326
Previously, we've passed `undefined` to the `queryFn` as `pageParam`, and you could assign a default value to the `pageParam` parameter in the `queryFn` function signature. This had the drawback of storing `undefined` in the `queryCache`, which is not serializable.
327327

328-
Instead, you now have to pass an explicit `defaultPageParam` to the infinite query options. This will be used as the `pageParam` for the first page:
328+
Instead, you now have to pass an explicit `initialPageParam` to the infinite query options. This will be used as the `pageParam` for the first page:
329329

330330
```diff
331331
useInfiniteQuery({
332332
queryKey,
333333
- queryFn: ({ pageParam = 0 }) => fetchSomething(pageParam),
334334
+ queryFn: ({ pageParam }) => fetchSomething(pageParam),
335-
+ defaultPageParam: 0,
335+
+ initialPageParam: 0,
336336
getNextPageParam: (lastPage) => lastPage.next,
337337
})
338338
```

docs/react/guides/prefetching.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const prefetchTodos = async () => {
3434
await queryClient.prefetchInfiniteQuery({
3535
queryKey: ['projects'],
3636
queryFn: fetchProjects,
37-
defaultPageParam: 0,
37+
initialPageParam: 0,
3838
getNextPageParam: (lastPage, pages) => lastPage.nextCursor,
3939
pages: 3 // prefetch the first 3 pages
4040
})

docs/react/reference/useInfiniteQuery.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const {
1515
} = useInfiniteQuery({
1616
queryKey,
1717
queryFn: ({ pageParam }) => fetchPage(pageParam),
18-
defaultPageParam: 1,
18+
initialPageParam: 1,
1919
...options,
2020
getNextPageParam: (lastPage, allPages, lastPageParam, allPageParams) =>
2121
lastPage.nextCursor,
@@ -33,7 +33,7 @@ The options for `useInfiniteQuery` are identical to the [`useQuery` hook](../ref
3333
- The function that the query will use to request data.
3434
- Receives a [QueryFunctionContext](../guides/query-functions#queryfunctioncontext)
3535
- Must return a promise that will either resolve data or throw an error.
36-
- `defaultPageParam: TPageParam`
36+
- `initialPageParam: TPageParam`
3737
- **Required**
3838
- The default page param to use when fetching the first page.
3939
- `getNextPageParam: (lastPage, allPages, lastPageParam, allPageParams) => TPageParam | undefined | null`

examples/react/algolia/src/useAlgolia.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default function useAlgolia<TData>({
2222
queryKey: ['algolia', indexName, query, hitsPerPage],
2323
queryFn: ({ pageParam }) =>
2424
search<TData>({ indexName, query, pageParam, hitsPerPage }),
25-
defaultPageParam: 0,
25+
initialPageParam: 0,
2626
getNextPageParam: (lastPage) => lastPage?.nextPage,
2727
staleTime,
2828
gcTime,

examples/react/infinite-query-with-max-pages/src/pages/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function Example() {
3535
const res = await axios.get('/api/projects?cursor=' + pageParam)
3636
return res.data
3737
},
38-
defaultPageParam: 0,
38+
initialPageParam: 0,
3939
getPreviousPageParam: (firstPage) => firstPage.previousId ?? undefined,
4040
getNextPageParam: (lastPage) => lastPage.nextId ?? undefined,
4141
maxPages: 3,

examples/react/load-more-infinite-scroll/src/pages/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function Example() {
3939
const res = await axios.get('/api/projects?cursor=' + pageParam)
4040
return res.data
4141
},
42-
defaultPageParam: 0,
42+
initialPageParam: 0,
4343
getPreviousPageParam: (firstPage) => firstPage.previousId ?? undefined,
4444
getNextPageParam: (lastPage) => lastPage.nextId ?? undefined,
4545
})

examples/svelte/load-more-infinite-scroll/src/lib/LoadMore.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
const query = createInfiniteQuery({
1010
queryKey: ['planets'],
1111
queryFn: ({ pageParam }) => fetchPlanets({ pageParam }),
12-
defaultPageParam: 1,
12+
initialPageParam: 1,
1313
getNextPageParam: (lastPage) => {
1414
if (lastPage.next) {
1515
const nextUrl = new URLSearchParams(new URL(lastPage.next).search)

packages/codemods/src/v5/rename-properties/__testfixtures__/rename-cache-time.input.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function useAlgolia<TData>({
3535
queryKey: ['algolia', indexName, query, hitsPerPage],
3636
queryFn: ({ pageParam }) =>
3737
search<TData>({ indexName, query, pageParam, hitsPerPage }),
38-
defaultPageParam: 0,
38+
initialPageParam: 0,
3939
getNextPageParam: (lastPage) => lastPage?.nextPage,
4040
staleTime,
4141
cacheTime,

packages/codemods/src/v5/rename-properties/__testfixtures__/rename-cache-time.output.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function useAlgolia<TData>({
3535
queryKey: ['algolia', indexName, query, hitsPerPage],
3636
queryFn: ({ pageParam }) =>
3737
search<TData>({ indexName, query, pageParam, hitsPerPage }),
38-
defaultPageParam: 0,
38+
initialPageParam: 0,
3939
getNextPageParam: (lastPage) => lastPage?.nextPage,
4040
staleTime,
4141
gcTime,

0 commit comments

Comments
 (0)