Course Content
React Mastery
React Mastery
Challenge: 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
anddescription
and provide the appropriate values. - To use these props within the child component
Card
, access them using dot notation sinceprops
is an object.
Thanks for your feedback!