useInfiniteQuery - lastPage and allPages explained visually

It wasn’t clear from Mosh’s lecture how lastPage and allPages worked. So I did a little snooping and figured it out.

Here’s the video of how it works: Loom | Free Screen & Video Recording Software | Loom

You start with a database of posts. lastPage basically means the most recently fetched post. It is either going to have a length of zero or one because there are more posts in the database to fetch or you’ve run out.

As you click the “load more” button the allPages array grows. Think of it as a posts bucket. It stores all the posts fetched in an array. The first click to “load more” makes length of allPages become two because one post page is shown by default - the first click then brings up the second page.

1 Like