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:
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
/booksendpoint. 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 runcurl localhost:3001/booksto see the list of books returned directly from the API.
