Junior
How to pass data from a parent component to a child component?
sobes.tech AI
Answer from AI
In React, data from a parent component is passed to a child component via props. The parent passes data as attributes to the child component, and the child receives them through the props object.
Example:
function Child(props) {
return <div>Hello, {props.name}!</div>;
}
function Parent() {
return <Child name="Alexey" />;
}
Here, Parent passes the string "Alexey" to the child component Child via the name prop. The child component uses this value for display.