Project: Pet Parade
by Andrew Nguyenยท Module 01 - Diving Into React

Introduction
Not Attempted
NameProgress
Course outline
Not Read
Key Concepts
Project: Pet Parade
Challenge 1
Not Attempted
Quiz 1
Not Attempted
Module 02 - Components and Props
Not Attempted
NameProgress
Project: Profile Card Creator
Not Read
Key Concepts
Not Read
Challenge 2
Not Attempted
Quiz 2
Not Attempted
Module 03 - State and Effect
Not Attempted
NameProgress
Key Concepts
Not Read
Project: Magic Garden
Not Read
Challenge 3
Not Attempted
Quiz 3
Not Attempted
Module 04 - Conditional Rendering
Not Attempted
NameProgress
Key Concepts
Not Read
Project: Weather Wardrobe
Not Read
Challenge 4
Not Attempted
Quiz 4
Not Attempted
Module 05: Handling Events
Not Attempted
NameProgress
Key Concepts
Not Read
Project: "Interactive Quiz App"
Not Read
Challenge 5
Not Attempted
Quiz 5
Not Attempted
Module 06 - Lists and Keys
Not Attempted
NameProgress
Key Concepts
Not Read
Project: "Photo Gallery"
Not Read
Challenge 6
Not Attempted
Quiz 6
Not Attempted
Module 07 - Forms and Validation
Not Attempted
NameProgress
Key Concepts
Not Read
Project: "Registration Form"
Not Read
Challenge 7
Not Read
Quiz 7
Not Attempted
Module 08 - Lifting State Up & Composition vs Inheritance
Not Attempted
NameProgress
Key Concepts
Not Read
Project: "Weather Dashboard"
Not Read
Challenge 8
Not Attempted
Quiz 8
Not Attempted
0 / 370 XP

Overview

In this hands-on project, we'll be creating a delightful "Pet Parade" that showcases your favorite animals. To start, we'll focus on displaying a dog with its name and picture. As we build this project, you'll apply what you've learned about JSX, rendering elements, and React components.

Goals

  • Learn to build a functional React component.

  • Understand how to pass data to components using props.

  • Practice rendering lists of data dynamically in React.

Instructions

Step 1: Create the Pet Component We'll start by creating a simple component that represents a pet. In your project's <strong>src</strong> folder, create a new file called <strong>Pet.js</strong>.

import React from 'react';

function Pet(props) {
  const { name, image } = props; // Destructuring. Read more: https://www.w3schools.com/react/react_es6_destructuring.asp
  // The above code is equivalent to:
  // const name = props.name;
  // const image = props.image;
  
  
  return (
    &lt;div className="pet"&gt;
      &lt;h2&gt;{name}&lt;/h2&gt;
      &lt;img src={image} alt={`Photo of ${name}`} style={{ width: "200px", height: "200px" }} /&gt;
    &lt;/div&gt;
  );
}

export default Pet;

This component accepts <strong>name</strong> and <strong>image</strong> as props and renders the pet's name and picture. Make sure to add some basic styling so the image fits nicely.

Step 3: Display Your Dog 

Now, integrate this <strong>Pet</strong> component into your main App component. Replace the content in <strong>App.js</strong> with the following:

import React from 'react';
import Pet from './Pet';

function App() {
  const myDog = {
    name: "Rex",
    image: "&lt;https://example.com/rex.jpg&gt;"  // Replace with an actual image URL of your dog
  };

  return (
    &lt;div className="App"&gt;
      &lt;header className="App-header"&gt;
        &lt;h1&gt;Welcome to the Pet Parade!&lt;/h1&gt;
        &lt;Pet name={myDog.name} image={myDog.image} /&gt;
      &lt;/header&gt;
    &lt;/div&gt;
  );
}

export default App;

Step 4: Testing 

Run your application and see if the dog's name and image are displayed correctly. You should see "Rex" (or your dog's name) along with their picture on the page.

 

Expanding the Project

Once you've got the basics down, let's move to the Challenge!

Maggie

Discuss with Maggie
Use the power of generative AI to interact with course content

Discussion

0 comments
Loading editor ...
Remember to be polite and report any undesirable behaviour

Category

Empty

Labels

Discussion has no labels

1 participant

user avatar

Priority

Notifications

You're not receiving notifications from this thread.
Course Outline