Virtualized Product Catalog
At Lenskart, our product catalog can grow to encompass thousands of eyewear products. Displaying such a large list efficiently is critical for a smooth user experience. A traditional approach of rendering all items simultaneously would lead to significant performance bottlenecks, especially on lower-end devices.
This problem challenges you to build a performant product listing page by implementing a virtualized list. You will render only the items currently visible in the viewport, plus a small buffer, ensuring a fluid scrolling experience even with a massive dataset.
Your primary task is to implement a React component that displays a large list of Lenskart products using a fixed-height virtualization strategy. You are provided with mock product data and basic styling.
VirtualizedProductList) that takes an array of Product objects as a prop.Product items that are currently visible within its scrollable container, plus a small buffer of items above and below the viewport.div with vertical scrolling enabled (overflow-y: auto).imageUrl, name, and price as provided in the mock data.TOTAL_PRODUCTS (e.g., 20-50 items, depending on viewport size) should be present in the DOM at any given time, regardless of the total number of products.name, price, and imageUrl for all visible products.10,000 products.ITEM_HEIGHT constant must be correctly utilized for calculations.Constraints
ITEM_HEIGHT is provided in App.tsx). You do not need to handle variable item heights.TOTAL_PRODUCTS = 10000 items. Your solution should scale efficiently for this number.useState, useEffect, useRef, useCallback, etc.).HTMLElement.scrollTop, HTMLElement.clientHeight, etc.react-window, react-virtualized). The goal is to implement the core logic yourself.Loading editor...