HomeInterview QuestionsBuild an infinite scroll list in React that loads …

Build an infinite scroll list in React that loads more products as the user scrolls, without clicking a next page. Ignore CSS; focus on functionality.

🟡 Medium Coding Junior level
1Times asked
Apr 2026Last seen
Apr 2026First seen

💡 Model Answer

To implement infinite scroll in React, keep a state array for products and a page counter. Render the list using map. Attach a scroll event listener to the container or use the IntersectionObserver API to detect when the user reaches the bottom. When the bottom is reached, increment the page counter and fetch the next batch of products from the API. Append the new products to the existing array. Use a loading flag to prevent duplicate requests while a fetch is in progress. Clean up the event listener or observer in useEffect’s cleanup function. Complexity: each fetch is O(k) where k is the page size; rendering is O(n) for n total items. This approach keeps the UI responsive and scales to large datasets.

This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.

🎤 Get questions like this answered in real-time

Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers — invisible to screen sharing.

Get Assisting AI — Starts at ₹500