Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/useInfiniteQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,20 @@ export function useInfiniteQuery(...args) {
data.push(await originalQueryFn(...args))
rebuiltPageVariables.push(args)
} else {
// get an up-to-date cursor based on the previous data set
const nextCursor = getGetFetchMore()(data[data.length - 1], data);

// break early if there's no next cursor
// otherwise we'll start from the beginning
// which will cause unwanted duplication
if (!nextCursor) {
break;
}

const pageArgs = [
// remove the last argument (the previously saved cursor)
...args.slice(0, -1),
// generate an up-to-date cursor based on the previous data set
getGetFetchMore()(data[data.length - 1], data),
nextCursor
]

data.push(await originalQueryFn(...pageArgs))
Expand Down