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


Final Project Structure

components
  ├── Book.jsx
  ├── data.js
App.jsx
index.js

1. Create the File Structure

  1. Inside the components folder, ensure you have the following files:

    • Book.jsx for the child component.

    • data.js (already provided).

  2. Inside src folder

    • App.jsx for the parent component.

data.js
// data.js
/** @format */

const booksData = {
  items: [
    {
      volume: {
        title: "Effective Java",
        subtitle: "Programming Language Guide",
        authors: ["Joshua Bloch"],
        description:
          "From the source of Java's design, this guide provides the best practices and expert insights for professional Java developers. Ideal for enhancing coding efficiency and understanding Java's capabilities.",
        image:
          "http://books.google.com/books/content?id=ka2VUBqHiWkC&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api",
      },
    },
    {
      volume: {
        title: "Clean Code",
        subtitle: "A Handbook of Agile Software Craftsmanship",
        authors: ["Robert C. Martin"],
        description:
          "A must-read for developers striving to write clean code that enhances readability and maintainability. Includes practical advice and real-world examples from software engineering.",
        image:
          "http://books.google.com/books/content?id=_i6bDeoCQzsC&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api",
      },
    },
    {
      volume: {
        title: "Head First Java",
        subtitle: "A Brain-Friendly Guide",
        authors: ["Kathy Sierra", "Bert Bates"],
        description:
          "An engaging, visually-rich approach to learning Java, suitable for beginners who want a complete understanding of object-oriented programming and Java basics.",
        image:
          "http://books.google.com/books/content?id=lXEBwv0LYogC&printsec=frontcover&img=1&zoom=5&source=gbs_api",
      },
    },
    {
      volume: {
        title: "Eloquent JavaScript, 3rd Edition",
        subtitle: "A Modern Introduction to Programming",
        authors: ["Marijn Haverbeke"],
        description:
          "Completely revised and updated, this best-selling introduction to programming in JavaScript focuses on writing real applications.",
        image:
          "http://books.google.com/books/content?id=FSVTDwAAQBAJ&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api",
      },
    },
    {
      volume: {
        title: "Professional Java for Web Applications",
        subtitle: "Comprehensive Guide to Spring Framework",
        authors: ["Nicholas S. Williams"],
        description:
          "The comprehensive Wrox guide for creating Java web applications for the enterprise This guide shows Java software developers and software engineers how to build complex web applications in an enterprise environment.",
        image:
          "http://books.google.com/books/content?id=cHr0AgAAQBAJ&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api",
      },
    },
  ],
};
export default booksData;

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

  1. Start the development server:

  2. 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