I would like to use react-query's useInfiniteQuery. Everything seems clear but the pagination, part.
The documentation exemple is:
export default () => {
const {
status,
data,
error,
isFetching,
isFetchingMore,
fetchMore,
canFetchMore,
} = useInfiniteQuery(
'projects',
async (key, nextId = 0) => {
const { data } = await axios.get('/api/projects?cursor=' + nextId)
return data
},
{
getFetchMore: lastGroup => lastGroup.nextId,
}
)
I understand what it does. projects is the id of the query, used for the cache, and then there is the function, that performs an api call. Now what about the nextId variable? It starts at zero, so the backend will know it must only return results from 0 to x (can we also pass a dynamic limit by the way?). But when fetchMore() - the function to trig the query again - is called, how on earth does useInfiniteQuery knows it should increment nextId?