Frontend School

Build a Dynamic Skeleton Loader for Course Cards

Machine Coding
medium

Build a Dynamic Skeleton Loader for Course Cards

Medium
React
Frontend
UI
Skeleton Loader
CSS

Overview

In modern web applications, perceived performance is as crucial as actual performance. When fetching data from an API, displaying a blank screen or a loading spinner can lead to a poor user experience. Skeleton loaders address this by providing a visual placeholder that mimics the layout of the content being loaded, giving users immediate feedback and making the waiting time feel shorter. This problem focuses on implementing a dynamic skeleton loader for a list of course cards, a common pattern in educational platforms like Upgrad.

What you need to do / Task

Your task is to create a set of React components that display course information and a corresponding skeleton loader. You will simulate a data fetching delay and dynamically switch between the skeleton loader and the actual content.

  1. Create a CourseCard component: This component will receive course data (title, instructor, duration, rating, image) and render it in a visually appealing card format.
  2. Create a CourseCardSkeleton component: This component should visually mimic the layout of the CourseCard but use placeholder shapes (e.g., rectangles, circles) instead of actual content. It should not receive any props.
  3. Integrate into App.tsx: In the main App component, use the provided mock course data and a simulated loading state (using setTimeout). Conditionally render a list of CourseCardSkeleton components while isLoading is true, and switch to rendering actual CourseCard components once isLoading becomes false.
  4. Implement skeleton animation: The CourseCardSkeleton should include a subtle animation (e.g., a shimmer or pulse effect) to indicate active loading.

UI/UX expectations

  • CourseCard Layout: Each card should clearly display the course image, title, instructor name, course duration, and rating. Consider a clean and organized layout.
  • CourseCardSkeleton Layout: The skeleton should closely resemble the CourseCard's structure. For instance, if CourseCard has an image at the top, the skeleton should have a placeholder rectangle of similar dimensions at the top. Text lines should be replaced by varying lengths of grey rectangles.
  • Grid Display: Both the actual course cards and their skeletons should be displayed in a responsive grid layout (e.g., 2-4 columns depending on screen size, though basic grid is sufficient for this problem).
  • Loading Animation: The skeleton placeholders should have a subtle, continuous animation (e.g., a left-to-right shimmer or a fading pulse effect) to visually convey that content is being loaded.

Acceptance criteria

  • The CourseCard component correctly renders all provided course details (image, title, instructor, duration, rating).
  • The CourseCardSkeleton component accurately mimics the visual structure and proportions of the CourseCard.
  • The application correctly displays CourseCardSkeleton components when isLoading is true.
  • The application correctly displays CourseCard components with actual data when isLoading is false.
  • The transition from skeleton to actual content occurs after a simulated delay.
  • The CourseCardSkeleton includes a noticeable, smooth loading animation (shimmer or pulse).
  • Multiple CourseCards or CourseCardSkeletons are displayed in a grid layout.

Constraints

Constraints & assumptions

  • You must use React (functional components and hooks).
  • You are required to implement the skeleton loader and its animation using only CSS (no external React skeleton libraries like react-loading-skeleton).
  • The loading state simulation should use setTimeout as provided in the starter code.
  • Focus on modern CSS (Flexbox or Grid for layout).
  • The problem focuses on the UI build; no API calls are required.

Out of scope

  • Extensive responsiveness beyond a basic grid layout for multiple columns.
  • Advanced state management libraries (e.g., Redux, Zustand).
  • Error handling for data fetching.
  • Accessibility attributes (e.g., aria-live) beyond basic semantic HTML.

What interviewers evaluate

  • Component Design & Reusability: How well the CourseCard and CourseCardSkeleton components are structured and how they interact.
  • CSS Implementation: Proficiency in creating complex layouts (grid) and animations (skeleton shimmer/pulse) using pure CSS.
  • State Management: Correct use of useState and useEffect to manage the loading state and simulate data fetching.
  • Attention to Detail: The visual fidelity of the skeleton loader in matching the actual content structure and the quality of the loading animation.

Loading editor...