Frontend School

Bigbasket Product Infinite Scroll

Machine Coding
easy

Bigbasket Product Infinite Scroll

Easy
React
TypeScript
Infinite Scroll
UI
Frontend

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.

  1. Display Products: Render the initial set of products fetched from the mock API.
  2. 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.
  3. Loading Indicator: Show a clear loading message or indicator while new products are being fetched.
  4. 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.
  5. 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).

Constraints

Constraints & assumptions

  • You must use React with TypeScript.
  • A mock fetchProducts function is provided, which simulates an asynchronous API call with pagination and network delay.
  • Assume a reasonable scroll threshold (e.g., loading when within 200 pixels of the bottom of the scrollable area).
  • The total number of products is finite; the mock API will eventually return an empty array to signify the end of the list.
  • The provided PAGE_SIZE constant should be used for fetching products.

Out of scope

  • Advanced error handling (e.g., retrying failed requests, displaying error messages for individual product fetches).
  • Complex UI elements like filters, sorting, or search functionality.
  • Responsive design beyond basic CSS provided.

What interviewers evaluate

  • Correct implementation of the infinite scroll logic using React hooks.
  • Effective state management for products, loading status, and pagination.
  • Clean, readable, and maintainable code structure.
  • Adherence to basic UI/UX requirements for loading and end-of-list states.

Loading editor...