Objectives:
- Passing Data with Props
- Understand how to pass data from a parent component to a child component using props.
- Destructuring Props
- Learn how to destructure props within the child component.
- Default Props
- Learn how to set default props for a component.
Exercises:
- Exercise 1: Passing Props to Components
- Modify the
Greeting
component to accept a name
prop and display a personalized greeting (e.g., "Welcome to React, [name]!").
- Pass the
name
prop from the App.jsx
file when rendering Greeting
.
- Exercise 2: Destructuring Props
- Refactor the
Greeting
component to use destructuring for the name
prop.
- Verify that the component still works as expected.
- Exercise 3: Passing Multiple Props
- Update the
UserInfo
component to accept name
, age
, and bio
as props.
- Pass these props from
App.jsx
and render the information accordingly.
- Use destructuring for these props in the
UserInfo
component.
- Exercise 4: Setting Default Props
- Set default values for the
age
and bio
props in UserInfo
.
- Test the component by rendering it without passing these props and verify that the default values are used.