Menu

Infinite lists in React
📰

Infinite lists in React

DEV Community: react·Giles Webberley·41 minutes ago
#vo98SoFI
#devtoreact#devto#dev#items#const
Reading 0:00
15s threshold

I have gone back to an app that I built using Spotify API because they have messed around with all sorts of things a basic app relies on, but that's another article!

The infinite loading hook

Something I was pleased with when returning though was how I had implemented infinite scrolling for the playlists and playlist tracks. Essentially I have used TanStack-Query's useInfiniteQuery() to collect 'pages' of data. A page can essentially be thought of as an object that has various properties including offset , limit , next , previous , and of course the items themselves. It tracks where abouts you are within the data collection. The fetching is quite confusing when you read it without checking out the documentation linked above but essentially the functions that you define for getNextPageParam etc are used internally by the TanStack query function and the merged function just makes sure your items are all in one array ( items ).…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.