27
loading...
This website collects cookies to deliver better user experience
class App extends Component {
constructor(props) {
super(props);
this.state = { data: "some data here" };
}
render() {
return (
<div>
<Child1 parentData={this.state.data} />
</div>
);
}
}
function Child1(props) {
return <div>The data we're getting is : {props.parentData}</div>;
}
class App extends Component {
constructor(props) {
super(props);
this.state = { data: "some data here" };
}
handleCallback = (childData) => {
this.setState({ data: childData });
};
render() {
return (
<div>
<Child1 parentData={this.state.data} />
<Child2 fromChild={this.handleCallback} />
</div>
);
}
}
class Child2 extends Component {
constructor(props) {
super(props);
this.state = {};
}
sendData = () => {
this.props.fromChild("data sent by the child");
};
render() {
return (
<div>
<button onClick={this.sendData}>Send data</button>
</div>
);
}
}