Overview
In this problem, you will implement an infinite scroll feed, a common pattern in social media and content-heavy applications. This pattern significantly enhances user experience by seamlessly loading more content as the user scrolls, avoiding explicit pagination. Your task is to build a React component that fetches and displays a list of user posts, continuously loading more data from a mock API as the user approaches the bottom of the feed.
What you need to do / Task
- Initial Data Load: On component mount, fetch and display the first page of posts.
- Infinite Scroll Logic: Implement logic to detect when the user has scrolled near the bottom of the feed container.
- Load More Data: When the scroll-to-bottom condition is met, fetch the next page of posts from the mock API and append them to the existing list.
- Loading Indicator: Display a clear loading indicator (e.g., "Loading more posts...") while data is being fetched. This indicator should disappear once new data is loaded or if there's no more data to fetch.
- End of Feed State: Once all available data has been fetched (i.e., the API returns an empty array or fewer items than requested), display a message indicating the end of the feed (e.g., "You've reached the end of the feed.").
UI/UX expectations
- Layout: The feed should display posts as a simple vertical list. Each post can be represented by its
id and content.
- Scroll Container: The entire list of posts should be scrollable within a fixed-height container, simulating a typical feed.
- Loading State: The loading indicator should be visible at the bottom of the feed while new data is being fetched.
- End State: The "end of feed" message should be visible at the bottom when no more data is available.
Acceptance criteria
- The component renders initially with the first page of posts.
- Scrolling down loads the next page of posts.
- A loading indicator is visible while new data is being fetched.
- The loading indicator disappears once data is loaded or fetching completes.
- Scrolling continuously loads more posts until all available data is fetched.
- A "You've reached the end of the feed." message is displayed when no more data can be loaded.
- The application does not attempt to fetch data unnecessarily (e.g., not fetching multiple times for a single scroll to bottom event).