Lesson 1 - Pulling Book Data from a Different Data File
Creating Book Component and Pulling Book Data from data.js
Step-by-Step Procedure to Create the React Components and Use booksData
booksDataFinal Project Structure
components
├── Book.jsx
├── data.js
App.jsx
index.js1. Create the File Structure
Inside the
componentsfolder, ensure you have the following files:Book.jsxfor the child component.data.js(already provided).
Inside src folder
App.jsxfor the parent component.
2. Create the Book.jsx Child Component
In BookList.jsx, define the functional component with props and state management:
3. Import and Use booksData in AppBookShelf.jsx
In AppBookShelf.jsx, pull the booksData from data.js, map over it, and render the Book components.
4. Install and Add Bootstrap Styling
Install Bootstrap via npm if not already installed:
Make sure to import Bootstrap CSS in main.jsx or globally:
5. Run the Application
Start the development server:
The application will display a styled book list where you can toggle the "read" status for each book.
This setup ensures a reusable Book component and a clean data flow from data.js to App.jsx.
Last updated