Frontend School

Build a Reusable Product Card Skeleton Loader

Machine Coding
easy

Build a Reusable Product Card Skeleton Loader

Easy
React
CSS
UI
Skeleton Loader
Animation

Overview

In e-commerce, a smooth user experience is paramount. When product data is being fetched, displaying a blank screen or a generic spinner can feel slow and unengaging. Skeleton loaders address this by providing a visual placeholder that mimics the structure of the content being loaded, improving perceived performance and user satisfaction. For a platform like Myntra, this is crucial for product listing pages (PLPs) where many items load simultaneously.

What you need to do / Task

Your task is to implement a reusable ProductCardSkeleton component that provides a visual placeholder for product cards while data is loading.

  1. Create ProductCardSkeleton Component: Implement a React functional component named ProductCardSkeleton in App.tsx.
  2. Mimic Product Card Structure: This component should visually represent the layout of a typical product card, including placeholders for an image, brand name, product title, and price.
  3. Implement Shimmer Animation: Apply a subtle "shimmer" or "pulse" animation to the skeleton elements to indicate active loading.
  4. Integrate into App.tsx: Conditionally render multiple instances of your ProductCardSkeleton component when data is loading, and switch to rendering actual ProductCard components once the data is available.

UI/UX expectations

  • Layout: The ProductCardSkeleton should have distinct placeholder shapes (e.g., a square/rectangle for the image, lines of varying widths for text, etc.) that roughly correspond to where content will eventually appear in a real product card.
  • Shimmer Animation: A smooth, continuous animation (e.g., a gradient moving across the skeleton elements) should be visible, indicating an active loading state.
  • Clarity: The skeleton should clearly communicate that content is on its way without being distracting.

Acceptance criteria

  • A ProductCardSkeleton component is defined and renders correctly.
  • The skeleton visually represents the structure of a product card (image, brand, title, price placeholders).
  • A CSS-based shimmer or pulse animation is applied to the skeleton elements.
  • The App component correctly displays multiple ProductCardSkeleton components when isLoading is true.
  • The App component correctly displays actual ProductCard components with mock data when isLoading becomes false.
  • The transition between skeleton and actual content is smooth and controlled by the isLoading state.

Constraints

Constraints & assumptions

  • You must use React (functional components) and CSS for styling.
  • No external UI component libraries (e.g., Material UI, Chakra UI) are allowed for the skeleton itself. You can use basic HTML elements and CSS.
  • The mock product data and a basic ProductCard component are provided.
  • The loading simulation (using setTimeout) is already set up in App.tsx.
  • Focus on the ProductCardSkeleton component and its integration, not complex data fetching or routing.

Out of scope

  • Extensive responsiveness for various screen sizes.
  • Advanced accessibility (ARIA attributes, keyboard navigation) for the skeleton loader.
  • Full styling of the actual ProductCard beyond basic display.
  • Error handling for data fetching.

What interviewers evaluate

  • Component Design: Ability to create a reusable and well-structured React component (ProductCardSkeleton).
  • CSS Proficiency: Effective use of CSS for layout, creating placeholder shapes, and implementing animations.
  • Conditional Rendering: Correct implementation of conditional UI rendering based on application state.
  • Code Quality: Readability, maintainability, and adherence to React best practices.

Loading editor...