Infinite query's fetchNextPage manual hasNextPage check
Hi,
I was wondering why fetchNextPage doesn't automatically check if there is a next page to fetch.
For example the docs give this example. I get why isFetching is not automatically checked but I can't find any logical reason for the hasNextPage not automatically be included in the fetchNextPage.
Anyone have some insights on why?
Thanks in advance!
3 Replies
environmental-rose•2w ago
This is my opinion, they want to give us freedom.
Let's say they settled with
fetchNextPage internally checking hasNextPage.
It would be a very subtle behavior that cannot be customized and controlled by the developerwise-white•2w ago
Just to play devils advocate - what exactly would you be fetching if you don't have a next page? Personally, I think that
fetchNextPage should sort of act like ensureQueryData in the sense that it should just return cached data for the last page, but I haven't had spent the time thinking about the edge cases like the maintainers would've.wise-white•7d ago
it's a good question. I don't think this was something that was given a ton of thought - the api predates my involvement (not something I get to say a lot 😂)
I guess calling a function that doesn't do anything isn't the best thing though
fetchNextPage just calls the queryFn and passes pageParam returned from getNextPageParam. Maybe someone wants to default that to something inside the fn, idk 😂