Overview
Bigbasket's online store offers a vast selection of products. To provide a seamless browsing experience, especially on category and search result pages, it's crucial to load products efficiently. This problem challenges you to implement an infinite scrolling mechanism for a product listing, allowing users to continuously discover items as they scroll down the page.
What you need to do / Task
Your primary task is to build a React component that displays a list of products and dynamically loads more items as the user scrolls towards the bottom of the list. You will be provided with a mock API that simulates fetching product data.
- Display Products: Render the initial set of products fetched from the mock API.
- Implement Infinite Scroll: Detect when the user scrolls near the bottom of the
product-list-container and trigger a call to fetch the next page of products.
- Loading Indicator: Show a clear loading message or indicator while new products are being fetched.
- End of List Notification: Display a message to the user once all available products have been loaded and there are no more items to fetch.
- Append Products: New products should be appended to the existing list, not replace them.
UI/UX expectations
- The product list should be contained within a scrollable area with a fixed height.
- Each product item should display its name and a placeholder image. Basic styling is provided.
- A text message like "Loading more products..." should appear at the bottom of the list when data is being fetched.
- A text message like "You've reached the end of the list." should appear when all products have been loaded and there's nothing left to fetch.
Acceptance criteria
- The initial set of products is displayed upon component mount.
- Scrolling down the
product-list-container triggers the loadProducts function when near the bottom.
- The loading indicator is visibly displayed only when
loadProducts is actively fetching data.
- Newly fetched products are correctly appended to the list of existing products.
- The "End of list" message is displayed correctly once
fetchProducts returns an empty array, signifying no more data.
- The scroll listener is efficiently managed (e.g., debounced or throttled if necessary, though not strictly required for this easy problem, or ensures
loadProducts is not called excessively).
- The component does not make unnecessary API calls (e.g., not calling
loadProducts if hasMore is false or loading is true).