Sobes.tech
Junior

Kuidas edastada andmeid vanemkomponendist lapsekomponendile?

sobes.tech AI

Vastus AI-lt

In React, data from the parent component are passed to the child component via properties (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="Aleksei" />;
}

Here, Parent passes the string "Aleksei" to the child component Child via the name prop. The child component uses this value to display it.