Challenge: Create Functional Components
Task: Creating an Encyclopedia Source
In this task, you will create an encyclopedia source of two cards. Each card will display an image and a description. The goal is to practice creating functional components and passing data to child components using props.
Instructions:
- Create a
Card
component as a reusable card template. - In the
Card
component, accept the following props:link
: The URL of the image for the card;alt
: The alternative text for the image;description
: The description text for the card.
- Use the
Card
component twice in theApp
component to create two cards with the following content:
Card 1 (About the Sun):
- Image URL:
https://codefinity-content-media.s3.eu-west-1.amazonaws.com/code-1/react/introduction-to-react/sun.png
- Alternative text: Provide an appropriate description.
- Description: "The sun shone brightly, casting a warm glow across the tranquil beach."
Card 2 (About the Mountain):
- Image URL:
https://codefinity-content-media.s3.eu-west-1.amazonaws.com/code-1/react/introduction-to-react/mountain.png
- Alternative text: Provide an appropriate description.
- Description: "The hiker gazed in awe at the majestic mountain towering before them."
Ensure that both the Card
and App
components are appropriately modified to display the cards correctly.
Here's a starter code with placeholders for you to complete:
- You can use the sameΒ
Card
Β component for both cards and control their content using props. - To pass the URL as a prop, create a prop calledΒ
link
Β and provide the URL as its value. Enclose the value in double quotes since it's a string. - Similarly, create props forΒ
alt
Β andΒdescription
Β and provide the appropriate values. - To use these props within the child componentΒ
Card
, access them using dot notation sinceΒprops
Β is an object.
Thanks for your feedback!
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Ask me questions about this topic
Summarize this chapter
Show real-world examples
Awesome!
Completion rate improved to 2.17
Challenge: Create Functional Components
Swipe to show menu
Task: Creating an Encyclopedia Source
In this task, you will create an encyclopedia source of two cards. Each card will display an image and a description. The goal is to practice creating functional components and passing data to child components using props.
Instructions:
- Create a
Card
component as a reusable card template. - In the
Card
component, accept the following props:link
: The URL of the image for the card;alt
: The alternative text for the image;description
: The description text for the card.
- Use the
Card
component twice in theApp
component to create two cards with the following content:
Card 1 (About the Sun):
- Image URL:
https://codefinity-content-media.s3.eu-west-1.amazonaws.com/code-1/react/introduction-to-react/sun.png
- Alternative text: Provide an appropriate description.
- Description: "The sun shone brightly, casting a warm glow across the tranquil beach."
Card 2 (About the Mountain):
- Image URL:
https://codefinity-content-media.s3.eu-west-1.amazonaws.com/code-1/react/introduction-to-react/mountain.png
- Alternative text: Provide an appropriate description.
- Description: "The hiker gazed in awe at the majestic mountain towering before them."
Ensure that both the Card
and App
components are appropriately modified to display the cards correctly.
Here's a starter code with placeholders for you to complete:
- You can use the sameΒ
Card
Β component for both cards and control their content using props. - To pass the URL as a prop, create a prop calledΒ
link
Β and provide the URL as its value. Enclose the value in double quotes since it's a string. - Similarly, create props forΒ
alt
Β andΒdescription
Β and provide the appropriate values. - To use these props within the child componentΒ
Card
, access them using dot notation sinceΒprops
Β is an object.
Thanks for your feedback!