"Load more" buttons are the easy way out. Real feeds โ Twitter, Instagram, your chat app โ load the next page the moment you scroll near the bottom. That magic is the Intersection Observer API, and it's much cleaner than the old scroll-listener + throttle dance.
This challenge gets you building an infinite scroll list of Rick & Morty characters with React 19's Suspense-driven use() fetching already in place. Your job: make the next page fetch itself.
๐งฉ Overview
Build an infinite scroll list of Rick and Morty characters using the Intersection Observer API โ the next page is fetched automatically when a sentinel element enters the viewport, building on an existing use() + Suspense data-fetching setup.
๐ https://www.reactchallenges.com/challenges/infinite-scroll
โ Requirements
- Keep the starter's
use()+ Suspense first-page fetch as the starting point - Follow the API pagination and read the next page URL from
data.info.next - Load the next page automatically when the user scrolls to the bottom โ no button
- Trigger the load from a sentinel element observed by the Intersection Observer
- Append new characters to the existing list instead of replacing them
- Show a loading indicator while the next page is being fetched
- Hide the loading indicator once the page finishes loading
- Show an end-of-list message when there are no more pages
- Stop fetching once the end is reached โ no requests when
info.nextisnull - Disconnect the observer when the component unmounts
๐ก Notes
-
Appis fully wired: title, layout, and the Suspense fallback are done โ all your work happens insideCharacters(). - The components file is read-only, and the API follows the classic
{ info: { next, prev }, results: [...] }Rick & Morty response shape. - Watch out: a couple of tests pass with the starter code simply because nothing fetches yet โ they only start validating real behavior once your observer is in place.
๐งช Tests
- renders the app title
- shows skeleton while loading
- renders first-page characters after loading
- observes the sentinel element
- loads the next page when the sentinel enters the viewport
- appends characters instead of replacing them
- loads the third page on repeated intersections
- shows a loading indicator while fetching the next page
- hides the loading indicator once the next page loads
- shows end of list when there are no more pages
- does not fetch again once the end is reached
- disconnects the observer on unmount
Infinite scroll is one of those tasks that shows up again and again in frontend interviews and real products.
Top comments (0)