Overview
In modern web applications, especially those dealing with large datasets like e-commerce product listings or social media feeds, efficient data loading is paramount. Infinite scrolling is a popular UI/UX pattern that enhances user experience by progressively loading content as the user scrolls down, eliminating the need for traditional pagination. This problem challenges you to implement a robust infinite scroll mechanism for a simulated product catalog.
What you need to do / Task
Your primary goal is to build a React component that displays a list of products and dynamically loads more products as the user scrolls towards the bottom of the page.
- Initial Load: Fetch and display the first set of products when the component mounts.
- Infinite Scroll Logic: Implement a mechanism to detect when the user has scrolled near the end of the current product list.
- Load More Products: When the scroll threshold is met, trigger a function to fetch the next batch of products from a simulated API.
- Display Products: Append the newly fetched products to the existing list, ensuring a continuous flow.
- Loading Indicator: Show a clear loading indicator (e.g., text or spinner) while new products are being fetched.
- End of List: Handle the scenario where all available products have been loaded. Display an appropriate message and stop further loading attempts.
UI/UX expectations
- Layout: Products should be displayed in a simple grid or list format. Each product card should show at least its name and price.
- Loading State: A visible message or spinner should appear at the bottom of the list when data is being fetched.
- End State: A distinct message (e.g., "You've reached the end of the catalog!") should be shown once all products are loaded and there are no more to fetch.
- Responsiveness: Basic readability on different screen sizes is expected, but complex responsive design is not a focus.
Acceptance criteria
- The application renders an initial set of products on load.
- Scrolling down the page triggers the loading of additional products.
- A loading indicator is displayed only when products are actively being fetched.
- Newly loaded products are appended to the existing list, without replacing previously loaded items.
- The loading mechanism correctly identifies when there are no more products to fetch and stops attempting to load further data.
- An "end of list" message is displayed when all products have been loaded.
- No duplicate products appear in the list.
- The UI remains responsive and smooth during scrolling and data loading.