class App extends React.Component {
constructor(props) {
super(props);
this.state = {
data: 'Initial data...'
}
this.updateState = this.updateState.bind(this);
};
updateState() {
this.setState({data: 'Data upDate from child component...'})
}
render() {
return (
<>
<Content myDataProp = {this.state.data} updateStateProp = {this.updateState}></Content>
</>
);
}
}
class Content extends React.Component {
render() {
return (
<>
<button onClick = {this.props.updateStateProp}>Click</button>
<h4>{this.props.myDataProp}</h4>
</>
);
}
}
ReactDOM.render(
<App />, document.getElementById('mountNode') );