Displaying Mock Data

Introduction: The Role of Mock Data in the Catalog

Welcome back! In the previous lessons, you learned how to set up a consistent layout for your React app and created some useful UI components, such as a search input and pagination control. Now, you are ready to see how these pieces come together to display real content — starting with mock data.

Mock data is sample information that you use to build and test your app before connecting to a real backend. In this lesson, you will learn how to display a list of books in your catalog using mock data. You will also see how to add search and pagination so users can easily browse and find books.

By the end of this lesson, you will know how to:

  • Show a list of books using a reusable component
  • Filter the list based on a search query
  • Split the list into pages with pagination

Let’s get started!

Using Mock Data for Catalog Development

As a quick reminder, your project is organized into features, and the catalog feature is where you will display your list of books. The mock data for the catalog is stored in a file called mockData.ts.

Here is what the mockData.ts file looks like:

TypeScript
// src/features/catalog/mockData.ts
export type Book = { id: number; title: string; author: string };

export const mockBooks: Book[] = [
  { id: 1, title: "Dune", author: "Frank Herbert" },
  { id: 2, title: "The Hobbit", author: "J.R.R. Tolkien" },
  { id: 3, title: "Project Hail Mary", author: "Andy Weir" },
  { id: 4, title: "1984", author: "George Orwell" },
  { id: 5, title: "Brave New World", author: "Aldous Huxley" },
  { id: 6, title: "Foundation", author: "Isaac Asimov" },
  { id: 7, title: "Hyperion", author: "Dan Simmons" },
  { id: 8, title: "Neuromancer", author: "William Gibson" },
  { id: 9, title: "Snow Crash", author: "Neal Stephenson" },
  { id: 10, title: "The Left Hand of Darkness", author: "Ursula K. Le Guin" },
];

This file exports a Book type and an array of book objects. Each book has an id, title, and author. You will use this data to display the catalog.

Note: In this lesson, the mock data is mainly a stand-in to help you understand how data is structured and how the UI will consume it. In the upcoming courses, we will move away from this static mock file and instead fetch books dynamically from our NestJS backend API, using a /books endpoint. If you are curious and want to peek ahead, the backend server is already part of this course. You can open a new terminal and run curl localhost:3001/books to see the list of books returned directly from the API.

Sign up

Join the 1M+ learners on CodeSignal

Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal