Responsive product card grid with infinite scroll fetching

Design and implement a component (React, or vanilla JavaScript using the starter HTML) that displays a list of products in a responsive Airbnb-style grid. The product data should be fetched from a remote API and displayed as individual cards. Your component must support infinite scroll: as the user scrolls down, new products should be fetched and appended to the grid seamlessly. The grid must remain responsive, and each card should clearly show the product’s image, title, and a short description. The Intersection Observer API is the usual way to detect when the user nears the end of the grid.
You will use the following API endpoint to fetch products:
GET https://fakestoreapi.com/products?limit=<limit>&page=<page>
limit (number): The number of products to fetch per request.page (number): The page number for pagination (starting from 1).Each product in the response is an object with at least these properties:
id (number): Unique identifier.title (string): Product name.description (string): Product description.image (string): URL to the product image.useState, useEffect, useRef). Vanilla: build the cards inside #grid and observe #loader.
// No input props. The component manages its own state and fetches data as needed.
// Renders a responsive grid of product cards. As the user scrolls, more cards are loaded and appended to the grid.
The user lands on the page. The first set of products is fetched from the API and displayed in a grid.
As the user scrolls to the bottom, the next set of products is automatically fetched and added to the grid.
Each product card displays:
- An image (from image) - The product title - A short description (first 100 characters of description) Loading indicators appear while more products are being fetched.
- Infinite scroll should feel seamless: there are no "Load More" buttons.
- If the API returns no products, or the user scrolls past all available products, the loading indicator should disappear or display an end-of-list message.
- The solution must efficiently manage state and avoid memory leaks by properly cleaning up the Intersection Observer.
The tests replace fetch with fake products and replace IntersectionObserver with a fake one that they trigger to simulate scrolling to the bottom. You don’t need test ids or specific class names. They only check that:
https://fakestoreapi.com/products?limit=<n>&page=1, and the next one asks for page=2.<img> whose src is the product’s image, the title, and only the first 100 characters of the description.