Props
Learn how to use props (properties) to pass data from parent components down to their child components.
Learning Goals
The Core Concept
Components are great, but they are static if they always display the exact same text. Props (short for 'properties') solve this. Props let you pass data down from a parent component to a child component, making components dynamic and reusable.
Think of props like HTML attributes (like src or href), or like function arguments. When a parent renders a child, it passes props as key-value attributes. The child component receives these props as a single JavaScript object parameter, which can be destructured to access individual values directly.
Visual guide
React concept flow
A simple original diagram to connect the lesson idea with real project flow.
Code & Implementation
// 1. Child component that receives props
// We destructure name and role directly in the parameter list
function UserCard({ name, role }) {
return (
<div style={{ border: '1px solid #ddd', padding: '16px', margin: '8px 0' }}>
<h3>{name}</h3>
<p>Role: {role}</p>
</div>
);
}
// 2. Parent component passing different data to the children
export default function TeamPage() {
return (
<div>
<h2>Meet the Team</h2>
<UserCard name="Alice" role="Lead Designer" />
<UserCard name="Marcus" role="Senior Engineer" />
</div>
);
}Expected Output
UI preview: - Heading 'Meet the Team' - Card 1: Alice, Role: Lead Designer - Card 2: Marcus, Role: Senior Engineer
Dynamic Product List
Hands-on practice task
The Challenge
Build a Product component that takes title and price as props. Render it inside a Shop component three times, passing different details and prices.
Helpful Hints
- •Define function Product({ title, price }) returning a styled div.
- •In Shop component, pass title and price props to each Product instance.
Quick Knowledge Check
Why can't I edit a prop inside the child component?
What is props.children?
Continue Learning
Next steps after this lesson
Build a Product component that takes title and price as props. Render it inside a Shop component three times, passing different details and prices.
Supercharge your career workflows!
Discover free online utilities to format data, build job applications, and automate your productivity routine with TechIdea.