Question presented to candidate: "React is often described as having unidirectional data flow. What does that actually mean, and why does it matter?"
What a strong answer should cover:
- Data moves one way — from parent to child through props. A child never writes to its parent state directly.
- The only upward path is invoking a callback the parent passed down. Summed up as "props down, events up".
- Props are read-only. Mutating one is a contract violation; React freezes props in development so the assignment throws.
- Why it matters: for any wrong value on screen there is exactly one owner, so debugging is a walk up the tree rather than a search of everything that could have written to it.
- The contrast is two-way binding (Angular's
ngModel, Vue'sv-model), where a child can write straight back into a parent's value — less boilerplate, but the write can come from anywhere. - Controlled components are the same rule applied to form inputs: value down, change event up.
- It does not mean data can only travel down the tree — Context and stores still exist. Those change where the value lives, not the direction it flows from its owner.
- Consequence: shared state gets lifted to a common ancestor.
Clarifying questions expected:
- "Do you want the principle, or how it plays out in forms and shared state?"
Code / implementation expected: Optional. A child calling a parent's callback demonstrates it in a few lines.