Closed yogeshtakeo closed 1 month ago
Learn how to use props in React to pass data between components and understand the role of props in component reusability and dynamic rendering.
npx create-vite@latest react-props-project # or npx create-react-app react-props-project
cd react-props-project npm install npm run dev # for Vite # or npm start # for Create React App
Create a Parent Component (e.g., App.js):
App.js
Create Child Components:
Header
title
Profile
name
age
bio
Button
label
Pass Props to Child Components:
Example:
import React from 'react'; import Header from './Header'; import Profile from './Profile'; import Button from './Button'; function App() { return ( <div> <Header title="Welcome to React Props Example" /> <Profile name="John Doe" age={30} bio="Software Developer" /> <Button label="Click Me" /> </div> ); } export default App;
Style Components:
Task: Understanding and Using React Props
Objective:
Learn how to use props in React to pass data between components and understand the role of props in component reusability and dynamic rendering.
Task Overviewå
Task Details
1. Review React Props
2. Set Up a React Project
3. Create Components and Pass Props
Create a Parent Component (e.g.,
App.js
):Create Child Components:
Header
- This component will receive atitle
prop and display it as a heading.Profile
- This component will receivename
,age
, andbio
props to display user information.Button
- This component will receive alabel
prop and display a button with that label.Pass Props to Child Components:
App.js
), pass the necessary data as props to each child component.Example:
Style Components:
4. Test and Refine
Task Submission