In React, data flows down the tree through props, and changes flow up through callbacks that the owner of the state provides. A child can't modify its parent's data directly. It asks the owner to change it, the owner updates its state, and React re-renders downward with the new props. Benefits: one owner per piece of state, predictable and traceable updates, easier debugging and testing, and a natural fit for React's "UI = f(state)" rendering. The trade-off is some extra wiring (lifting state, passing callbacks) compared with two-way binding.
function TemperatureConverter() {
const [celsius, setCelsius] = useState(20); // single owner
return (
<>
<TemperatureInput
label="Celsius"
value={celsius}
onChange={setCelsius}
/>
<TemperatureInput
label="Fahrenheit"
value={celsius * 9 / 5 + 32}
onChange={f => setCelsius((f - 32) * 5 / 9)}
/>
</>
);
}
function TemperatureInput({ label, value, onChange }) {
return (
<label>
{label}
<input
type="number"
value={Number(value.toFixed(2))}
onChange={e => onChange(Number(e.target.value))}
/>
</label>
);
}
Both inputs display data derived from one source of truth. Neither input owns temperature state. They report user intent upward, and the parent decides.
Frameworks like AngularJS (ng-model) or Vue's v-model sync a value both ways automatically. That's convenient, but with many bindings changes can cascade unpredictably. Modern Vue and Angular still keep one-way flow underneath (v-model is sugar for a prop plus an event). React makes the "event up" half explicit.
children) avoids drilling through intermediate layers.Spotted a mistake or a rights concern? Report an issue