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.
- Initial Load: Fetch and display the first page of articles when the component mounts.
- Scroll Detection: Implement a mechanism to detect when the user has scrolled near the bottom of the article feed container.
- Load More: When the scroll threshold is met, trigger a call to fetch the next page of articles.
- Append Articles: Append the newly fetched articles to the existing list, ensuring the user sees a continuous flow of content.
- Loading Indicator: Display a visible loading indicator at the bottom of the feed while new articles are being fetched.
- 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.