Frontend School

Infinite Scroll Article Feed

Machine Coding
easy

Infinite Scroll Article Feed

Easy
React
JavaScript
Infinite Scroll
UI

Overview

Modern web applications often deal with large datasets, and presenting all data at once can be overwhelming and inefficient. Infinite scroll is a common UI/UX pattern used to progressively load content as the user scrolls down a page, providing a seamless browsing experience. For this problem, you will build a simple article feed that loads more articles automatically as the user approaches the bottom of the page.

What you need to do / Task

Your task is to implement an infinite scroll mechanism for a list of articles using React. You will be provided with a mock API function that simulates fetching paginated data.

  1. Initial Load: Fetch and display the first page of articles when the component mounts.
  2. Scroll Detection: Implement a mechanism to detect when the user has scrolled near the bottom of the article feed container.
  3. Load More: When the scroll threshold is met, trigger a call to fetch the next page of articles.
  4. Append Articles: Append the newly fetched articles to the existing list, ensuring the user sees a continuous flow of content.
  5. Loading Indicator: Display a visible loading indicator at the bottom of the feed while new articles are being fetched.
  6. Stop Loading: Once all available articles have been loaded (or the mock API indicates no more data), stop attempting to fetch new articles and hide the loading indicator.

UI/UX expectations

  • The articles should be displayed as a vertical list, each with a title and a short body.
  • A simple visual indicator (e.g., a spinner or text like "Loading more...") should appear at the bottom of the list when new data is being fetched.
  • The articles should appear seamlessly without refreshing the page as new content loads.

Acceptance criteria

  • Upon initial render, the first set of articles is displayed.
  • Scrolling down the page triggers a fetch for more articles.
  • Newly fetched articles are appended to the existing list without replacing them.
  • A loading indicator is visible at the bottom of the feed while data is being fetched.
  • The loading indicator disappears once new data has been loaded or if there are no more articles to fetch.
  • No further fetch requests are made once all mock articles have been loaded.

Constraints

Constraints & assumptions

  • You must use React for this implementation.
  • The provided fetchArticles mock function simulates an asynchronous API call with pagination. It will return an empty array when no more articles are available.
  • Assume the container holding the articles will be scrollable.
  • Focus on functional components and React Hooks.
  • No need for advanced error handling beyond what's provided by the mock API (e.g., network errors are out of scope).

Out of scope

  • Virtualization for extremely long lists.
  • Complex caching strategies.
  • Server-side rendering or advanced routing.
  • Accessibility features beyond basic semantic HTML.

What interviewers evaluate

  • Correct and robust implementation of the infinite scroll mechanism.
  • Effective use of React state and lifecycle hooks (useState, useEffect).
  • Clean and readable component structure and event handling.
  • Appropriate display and management of the loading state.

Loading editor...