Props (Properties) are the mechanism used to pass data from a parent component down to its children.
Parent Component → sends data → Child Component
The App component controls the data. Each Student component simply receives and displays what it's given.
A child component cannot change its props. They are "Locked."
// Correct ✅ props.name // Wrong ❌ (This will cause an error) props.name = "John";
Data only flows down from Parent to Child.
Passed exactly like HTML attributes: <Component key="value" />
<Student name="Ravi" age="20" />
function Student(props) {
return (
<h1>{props.name}</h1>
);
}
Student.js (Child)
export default function Student(props) {
return (
<div>
<h2>Name: {props.name}</h2>
<p>Age: {props.age}</p>
</div>
);
}
App.js (Parent)
import Student from "./Student";
function App() {
return (
<div>
<Student name="Ravi" age="20" />
<Student name="Anu" age="21" />
</div>
);
}
| Feature | Props | State |
|---|---|---|
| Source | From Parent | Inside Component |
| Editable | No (Read-only) | Yes |
| Flow | Parent to Child | Internal |
| Purpose | Pass configuration | Manage changes |
This is the preferred, cleaner way to write components today.
// Old Way ❌
function Student(props) {
return <h1>{props.name}</h1>;
}
// Better Way (Destructuring) ✅
function Student({ name, age }) {
return (
<div>
<h1>{name}</h1>
<p>{age}</p>
</div>
);
}
Challenge: Use the Student component three times in App.js with different names.
Components → JSX → Props (Complete)
↓
Next: State → Events → Hooks