React follows a unidirectional (one-way) data flow, meaning:
Data flows from parent components → down to child components (via props).
In other words, state is owned by a parent component, and children receive data — they cannot modify that data directly.
🧩 Example
function Parent() {
const [name, setName] = useState("Dev");
return <Child name={name} onChangeName={setName} />;
}
function Child({ name, onChangeName }) {
return (
<div>
<p>{name}</p>
<button onClick={() => onChangeName("Teekam")}>Change Name</button>
</div>
);
}
Parentholds the state (name).Childreceives it via props.Childcan’t modify it directly — it can only request a change via a callback (onChangeName).
✅ This ensures that data has a single, clear source of truth.
🔁 How the Flow Works
- Parent holds the state
- Parent passes data via props → down to children
- Child components display data
- If a child needs to update data → it calls a callback function from the parent
- Parent updates state → triggers a re-render → new data flows back down
🌊 Visual Representation
[ Parent Component (state) ]
|
↓
props / callbacks
↓
[ Child Component ]
No data flows upwards automatically — it must go through callbacks.
💪 Benefits of One-Way Data Flow
| Benefit | Explanation |
|---|---|
| 🧠 Predictability | Since data only moves in one direction, it’s easy to trace where a change originates. |
| 💡 Easier Debugging | You can track state changes from top to bottom — no circular dependencies. |
| ⚡ Better Performance | React only re-renders the parts of the UI affected by state changes. |
| 🔒 Data Integrity | Children can’t accidentally mutate shared data. |
| 🔁 Component Reusability | Child components stay pure and reusable — they just display data, not own it. |
| 🧩 Simpler State Management | State logic lives in predictable, centralized places (often top-level or context). |
🧱 In summary
React’s one-way data flow means data always flows from parent → child through props, and any updates flow back up via callbacks.
This approach makes your UI:
- predictable ✅
- easy to debug ✅
- consistent with React’s declarative model ✅