You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(infiniteQuery): type pageParams and allow null cursors (#5811)
* type pageParams and allow null cursors
* doc
* use TPageParam in some places [WIP]
* dont pluralize
* docs: document return value in api-reference
* docs: migration guide
* refactor: use != null to check for null and undefined
* fix: we also need to widen the check in `fetchPage`
* test: check for null returned from getNextPageParam
* more
* fix react type test
* dont need that i guess
* prettier
* migration guide
* revert generic order
* format
* fix test
---------
Co-authored-by: Dominik Dorfmeister <[email protected]>
Copy file name to clipboardExpand all lines: docs/react/guides/infinite-queries.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,8 +13,8 @@ When using `useInfiniteQuery`, you'll notice a few things are different:
13
13
- The `fetchNextPage` and `fetchPreviousPage` functions are now available (`fetchNextPage` is required)
14
14
- The `defaultPageParam` option is now available (and required) to specify the initial page param
15
15
- 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
16
-
- A `hasNextPage` boolean is now available and is `true` if `getNextPageParam` returns a value other than `undefined`
17
-
- A `hasPreviousPage` boolean is now available and is `true` if `getPreviousPageParam` returns a value other than `undefined`
16
+
- A `hasNextPage` boolean is now available and is `true` if `getNextPageParam` returns a value other than `null` or `undefined`
17
+
- A `hasPreviousPage` boolean is now available and is `true` if `getPreviousPageParam` returns a value other than `null` or `undefined`
18
18
- The `isFetchingNextPage` and `isFetchingPreviousPage` booleans are now available to distinguish between a background refresh state and a loading more state
19
19
20
20
> Note: Options `initialData` or `placeholderData` need to conform to the same structure of an object with `data.pages` and `data.pageParams` properties.
Copy file name to clipboardExpand all lines: docs/react/guides/migrating-to-v5.md
+23-24Lines changed: 23 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -341,6 +341,10 @@ useInfiniteQuery({
341
341
342
342
Previously, we've allowed to overwrite the `pageParams` that would be returned from `getNextPageParam` or `getPreviousPageParam` by passing a `pageParam` value directly to `fetchNextPage` or `fetchPreviousPage`. This feature didn't work at all with refetches and wasn't widely known or used. This also means that `getNextPageParam` is now required for infinite queries.
343
343
344
+
### Returning `null` from `getNextPageParam` or `getPreviousPageParam` now indicates that there is no further page available
345
+
346
+
In v4, you needed to explicitly return `undefined` to indicate that there is no further page available. We've widened this check to include `null`.
347
+
344
348
### No retries on the server
345
349
346
350
On the server, `retry` now defaults to `0` instead of `3`. For prefetching, we have always defaulted to `0` retries, but since queries that have `suspense` enabled can now execute directly on the server as well (since React18), we have to make sure that we don't retry on the server at all.
@@ -401,8 +405,6 @@ Lastly the a new derived `isLoading` flag has been added to the queries that is
401
405
To understand the reasoning behing this change checkout the [v5 roadmap discussion](https://github.com/TanStack/query/discussions/4252).
402
406
403
407
[//]: #'FrameworkBreakingChanges'
404
-
405
-
406
408
[//]: #'NewFeatures'
407
409
408
410
## New Features 🚀
@@ -414,29 +416,26 @@ v5 also comes with new features:
414
416
We have a new, simplified way to perform optimistic updates by leveraging the returned `variables` from `useMutation`:
Here, we are only changing how the UI looks when the mutation is running instead of writing data directly to the cache. This works best if we only have one place where we need to show the optimistic update. For more details, have a look at the [optimistic updates documentation](../guides/optimistic-updates).
- When new data is received for this query, this function receives both the last page of the infinite list of data and the full array of all pages, as well as pageParam information.
42
42
- It should return a **single variable** that will be passed as the last optional parameter to your query function.
43
-
- Return `undefined` to indicate there is no next page available.
- When new data is received for this query, this function receives both the first page of the infinite list of data and the full array of all pages, as well as pageParam information.
46
46
- It should return a **single variable** that will be passed as the last optional parameter to your query function.
47
-
- Return `undefined` to indicate there is no previous page available.
47
+
- Return `undefined`or `null`to indicate there is no previous page available.
48
48
-`maxPages: number | undefined`
49
49
- The maximum number of pages to store in the infinite query data.
50
50
- When the maximum number of pages is reached, fetching a new page will result in the removal of either the first or last page from the pages array, depending on the specified direction.
0 commit comments