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: remove manual mode for infinite queries
* refactor: simplify checking for next / previous fetch
* types: better typings for fetchMeta.direction
* refactor: fix hasNextPage / hasPreviousPage
we should always return a boolean here, and according to the docs and the implementation in infiniteQueryBehaviour, we will only stop fetching if we return `undefined` from `getNextPageParam` or `getPreviousPageParam`. The checks for `false` or `null` on this boolean were likely wrong
* fix: hasNextPage / hasPreviousPage is now always a boolean
* feat: defaultPageParam
* types: defaultPageParam is mandatory
* fix: we also need `defaultPageParam` for `fetchInfiniteQuery` now
* test: fix some assertions that relied on `undefined` being in `pageParams`
* add some failing tests to show the problem with pageParam typings
* feat: add PageParam typing (#5005)
* feat: add PageParam typing
* feat(infinite-query): more typing
* feat(infinite-query): make pageParam never by defaukt
* feat(infinite-query): PageParam type unknown for infinite queries
* fix(infinite-query): fix tests
* feat(infinite-query): add previous end next return TPageParam type
* revert changes to pnpm-lock.yaml
* types: add TPageParam to other framework adapters
* fix(vue-query): correct generic typing
* types: rename InfiniteQueryOptions to InfiniteQueryPageParamsOptions
because it might be mistaken for a full set of options, which it is not
* types: add failing select tests
* fix formatting (new prettier version on v5)
* types: add types for FetchMeta everywhere
* feat(select): defer TData inference (#5040)
* feat(select): defer TData inference
* test(select): restore test
* fix(select): change InfiniteQuery Observer definition
* fix(infinite-queries): fix solid type inference select
* fix(infinite-queries): fix solid type inference select
* chore(infinite-queries): fix prettier
* fix(infinite-queries): fix vue and svelte types
* fix(infinite-queries): fix react type inference select
* chore(infinite-queries): fix imports
* style: fix prettier warnings
* docs: docs for new infinite query features
* docs: examples use new syntax
---------
Co-authored-by: ecyrbe <[email protected]>
Co-authored-by: Damian Osipiuk <[email protected]>
Copy file name to clipboardExpand all lines: docs/react/guides/infinite-queries.md
+10-41Lines changed: 10 additions & 41 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -103,42 +103,11 @@ function Projects() {
103
103
104
104
When an infinite query becomes `stale` and needs to be refetched, each group is fetched `sequentially`, starting from the first one. This ensures that even if the underlying data is mutated, we're not using stale cursors and potentially getting duplicates or skipping records. If an infinite query's results are ever removed from the queryCache, the pagination restarts at the initial state with only the initial group being requested.
105
105
106
-
## What if I need to pass custom information to my query function?
107
-
108
-
By default, the variable returned from `getNextPageParam` will be supplied to the query function, but in some cases, you may want to override this. You can pass custom variables to the `fetchNextPage` function which will override the default variable like so:
## What if I want to implement a bi-directional infinite list?
138
107
139
108
Bi-directional lists can be implemented by using the `getPreviousPageParam`, `fetchPreviousPage`, `hasPreviousPage` and `isFetchingPreviousPage` properties and functions.
140
109
141
-
[//]: #'Example4'
110
+
[//]: #'Example3'
142
111
143
112
```tsx
144
113
useInfiniteQuery({
@@ -149,13 +118,13 @@ useInfiniteQuery({
149
118
})
150
119
```
151
120
152
-
[//]: #'Example4'
121
+
[//]: #'Example3'
153
122
154
123
## What if I want to show the pages in reversed order?
155
124
156
125
Sometimes you may want to show the pages in reversed order. If this is case, you can use the `select` option:
157
126
158
-
[//]: #'Example5'
127
+
[//]: #'Example4'
159
128
160
129
```tsx
161
130
useInfiniteQuery({
@@ -168,13 +137,13 @@ useInfiniteQuery({
168
137
})
169
138
```
170
139
171
-
[//]: #'Example5'
140
+
[//]: #'Example4'
172
141
173
142
## What if I want to manually update the infinite query?
Copy file name to clipboardExpand all lines: docs/react/guides/migrating-to-v5.md
+21-1Lines changed: 21 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -248,7 +248,7 @@ This in turn will enable other frameworks to have the same functionality in a fr
248
248
import { queryClient } from './my-client'
249
249
250
250
const { data } = useQuery(
251
-
{
251
+
{
252
252
queryKey: ['users', id],
253
253
queryFn: () => fetch(...),
254
254
- context: customContext
@@ -265,6 +265,26 @@ However, refetching all pages might lead to UI inconsistencies. Also, this optio
265
265
266
266
The v5 includes a new `maxPages` option for infinite queries to limit the number of pages to store in the query data and to refetch. This new feature handles the use cases initially identified for the `refetchPage` page feature without the related issues.
267
267
268
+
### Infinite queries now need a `defaultPageParam`
269
+
270
+
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.
271
+
272
+
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:
### Manual mode for infinite queries has been removed
285
+
286
+
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 `getNextPagParam` is now required for infinite queries.
0 commit comments