Frontend School

Build a Product Grid with Skeleton Loading

Machine Coding
easy

Build a Product Grid with Skeleton Loading

Easy
UI
React
CSS
Frontend
Skeleton Loader
User Experience

Overview

Modern web applications prioritize a seamless user experience, even during data fetching. When content takes time to load, displaying a blank screen can be jarring. Skeleton loaders provide a visual placeholder that mimics the layout of the actual content, giving users immediate feedback that content is on its way, thereby improving perceived performance and reducing user frustration. In this problem, you will implement a skeleton loader for a product display grid.

What you need to do / Task

Your primary task is to enhance a simple product display page by implementing a skeleton loading state. Specifically, you need to:

  1. Create a ProductCard component: This component will display the details of a single product (image, name, description, price).
  2. Create a SkeletonProductCard component: This component will serve as a visual placeholder for a ProductCard while data is loading. It should visually resemble the ProductCard's structure but with generic placeholder shapes.
  3. Integrate Loading Logic: In the main App component, simulate data fetching using the provided fetchProducts utility. During the loading phase, display multiple instances of the SkeletonProductCard.
  4. Transition to Content: Once the simulated data fetching is complete, replace the SkeletonProductCard instances with actual ProductCard components populated with the fetched data.
  5. Implement Skeleton Animation: Add a subtle, continuous animation (e.g., a shimmer or pulse effect) to the SkeletonProductCard elements to indicate active loading.

UI/UX expectations

  • Product Card: Each product card should clearly display an image, a product name, a brief description, and its price. The layout should be clean and readable.
  • Skeleton Card: The SkeletonProductCard should closely mirror the layout structure of the ProductCard. For instance, a large rectangle for the image, and several lines or smaller rectangles for text (title, description, price).
  • Animation: The skeleton loader should have a subtle, non-distracting animation (like a left-to-right shimmer or a gentle pulse) to indicate activity. This should be implemented using CSS animations.
  • Responsiveness: While not the primary focus, ensure the product grid adapts reasonably well to different screen sizes using basic CSS grid/flexbox properties.

Acceptance criteria

  • The application initially displays a grid of SkeletonProductCard components.
  • After a simulated delay (e.g., 2 seconds), the SkeletonProductCard components are replaced by actual ProductCard components displaying mock product data.
  • Each ProductCard correctly renders the product's image, name, description, and price.
  • Each SkeletonProductCard visually matches the layout of a ProductCard (e.g., placeholder for image, title, description, price).
  • The SkeletonProductCard components have a continuous, subtle CSS animation (e.g., shimmer or pulse).
  • The transition from skeleton to actual content is smooth, without significant layout shifts.

Constraints

Constraints & assumptions

  • You must use React (functional components and hooks) and CSS for the solution.
  • No external UI component libraries (e.g., Material UI, Ant Design) should be used for the core skeleton/card components. You are expected to implement the UI and animations with plain CSS.
  • The data fetching is simulated using a setTimeout function, as provided in the starter code. You do not need to implement actual API calls.
  • Focus on clear component separation and clean, readable code.

Out of scope

  • Advanced accessibility features beyond basic semantic HTML.
  • Complex state management solutions (e.g., Redux, Zustand).
  • Server-side rendering.
  • Robust error handling for data fetching.
  • Deep responsiveness for all device types; basic grid adaptation is sufficient.

What interviewers evaluate

  • Ability to structure React components effectively and manage component state.
  • Proficiency in CSS for layout, styling, and animations.
  • Understanding of perceived performance and user experience principles.
  • Code quality, readability, and adherence to best practices.

Loading editor...