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
Copy file name to clipboardExpand all lines: docs/src/pages/guides/infinite-queries.md
+40-28Lines changed: 40 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,10 +8,11 @@ Rendering lists that can additively "load more" data onto an existing set of dat
8
8
When using `useInfiniteQuery`, you'll notice a few things are different:
9
9
10
10
-`data` is now an array of arrays that contain query group results, instead of the query results themselves
11
-
- A `fetchMore` function is now available
12
-
- A `getFetchMore` option is 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 (which can optionally be overridden when calling the `fetchMore` function)
13
-
- A `canFetchMore` boolean is now available and is `true` if `getFetchMore` returns a truthy value
14
-
- An `isFetchingMore` boolean is now available to distinguish between a background refresh state and a loading more state
11
+
- The `fetchNextPage` and `fetchPreviousPage` functions are now available
12
+
- 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 (which can optionally be overridden when calling the `fetchNextPage` or `fetchPreviousPage` functions)
13
+
- A `hasNextPage` boolean is now available and is `true` if `getNextPageParam` returns a value other than `undefined`.
14
+
- A `hasPreviousPage` boolean is now available and is `true` if `getPreviousPageParam` returns a value other than `undefined`.
15
+
- The `isFetchingNextPage` and `isFetchingPreviousPage` booleans are now available to distinguish between a background refresh state and a loading more state
With this information, we can create a "Load More" UI by:
32
33
33
34
- Waiting for `useInfiniteQuery` to request the first group of data by default
34
-
- Returning the information for the next query in `getFetchMore`
35
-
- Calling `fetchMore` function
35
+
- Returning the information for the next query in `getNextPageParam`
36
+
- Calling `fetchNextPage` function
36
37
37
-
> Note: It's very important you do not call `fetchMore` with arguments unless you want them to override the `fetchMoreInfo` data returned from the `getFetchMore` function. eg. Do not do this: `<button onClick={fetchMore} />` as this would send the onClick event to the `fetchMore` function.
38
+
> Note: It's very important you do not call `fetchNextPage` with arguments unless you want them to override the `pageParam` data returned from the `getNextPageParam` function. eg. Do not do this: `<button onClick={fetchNextPage} />` as this would send the onClick event to the `fetchNextPage` function.
@@ -91,7 +92,7 @@ When an infinite query becomes `stale` and needs to be refetched, each group is
91
92
92
93
## What if I need to pass custom information to my query function?
93
94
94
-
By default, the info returned from `getFetchMore` will be supplied to the query function, but in some cases, you may want to override this. You can pass custom variables to the `fetchMore` function which will override the default info like so:
95
+
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 infinitely load more data in reverse?
118
+
## What if I want to implement a bi-directional infinite list?
118
119
119
-
Sometimes you may not want to **append** infinitely loaded data, but instead **prepend** it. If this is case, you can use `fetchMore`'s `previous` option, eg.
120
+
Bi-directional lists can be implemented by using the `getPreviousPageParam`, `fetchPreviousPage`, `hasPreviousPage` and `isFetchingPreviousPage` properties and functions.
- This function allows you to fetch the next "page" of results.
37
-
-`fetchMoreVariableOverride` allows you to optionally override the fetch more variable returned from your `getFetchMore` option to your query function to retrieve the next page of results.
38
-
-`canFetchMore: boolean`
39
-
- If using `paginated` mode, this will be `true` if there is more data to be fetched (known via the required `getFetchMore` option function).
48
+
-`options.pageParam: unknown` allows you to manually specify a page param instead of using `getNextPageParam`.
0 commit comments