1

Like the title explains, I can't seem to get the next set of results/page on request using react-query infiniteQuery. I also made a snack from their example code but still nothing.

It looks like the pageParam never gets incremented when fetchNextPage is called. I've tried version 3 and 4 with same results.

So I'm not sure if I should be incrementing the nextCursor manually. I can see nothing in the docs that suggests that I have to do so.

snack example

const fetchProjects = async ({ pageParam = 0 }) => {
 const res = await fetch(`https://api.instantwebtools.net/v1/passenger? 
 page=${pageParam}&size=10`)
 return res.json()
}

const List = () => {
  const {
  data,
  error,
  fetchNextPage,
  hasNextPage,
  isFetching,
  isFetchingNextPage,
  status,
} = useInfiniteQuery({
  queryKey: ['test'],
  queryFn: fetchProjects,
  getNextPageParam: (lastPage, pages) => lastPage.nextCursor,
});

const loadMore = () => {
  fetchNextPage()
}

1 Answer 1

1

Turns out the API I was using as test does not return any way for me to tell if there is more data to fetch. ie. no nextCursor property.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.