11. What is one-way data flow in React?
One-way data flow means data moves in a single direction: from parent components to child components through props. This makes applications easier to understand, debug, and maintain because the source of data is predictable.
Example
function Parent() {
const name = "Bhuvanesh";
return <Child name={name} />;
}
function Child(props) {
return <h1>{props.name}</h1>;
}In this example, Parent passes data to Child, but Child cannot directly change the parent's data.
Summary: React follows one-way data flow where data travels from parent to child via props, making state changes predictable and easier to manage.