Overview
In modern web applications, especially those that are image-heavy like social media feeds or e-commerce product listings, loading all images upfront can severely impact initial page load time and user experience. Lazy loading is a crucial technique that defers the loading of off-screen images until the user scrolls them into the viewport, significantly improving performance and resource utilization. This problem challenges you to implement a basic image gallery with lazy loading.
What you need to do / Task
Your primary task is to build a React component that displays a collection of images. All images should be lazy-loaded, meaning their actual content (the src attribute) should only be fetched and rendered when they are about to become visible in the user's viewport.
- Render a grid of images using the provided mock data.
- Implement lazy loading for all images in the gallery.
- Ensure a visual placeholder is shown for images that are not yet loaded.
UI/UX expectations
- The application should display a scrollable grid layout of image cards.
- Each image card should contain an image and a title/description.
- Images should only load their actual content when they are about to enter or are within the user's viewport.
- Before an image loads, a simple placeholder (e.g., a gray box) should be visible in its place.
- The gallery should be responsive and provide a smooth scrolling experience.
Acceptance criteria
- Images are not loaded until they are scrolled into view (verifyable via network tab).
- A visible placeholder is displayed for images before their actual content loads.
- The application remains responsive during scrolling and image loading.
- All images eventually load correctly when scrolled into view.
- The gallery displays all provided mock images.