import React from 'react';
import ReactDOM from 'react-dom';
const Counter = ({ value }) => (
<p>State value is: {value}</p>
);
class App extends React.Component {
constructor(props) {
super(props);
this.state = { value: 42 };
}
handleOnClick = () => {
this.setState(prevState => ({ value: prevState.value + 1 }));
}
render() {
return (
<div style={{ fontSize: '1.2em', margin: '1em' }}>
<Counter value={this.state.value} />
<button onClick={this.handleOnClick}>INCREMENT</button>
</div>
);
}
}
ReactDOM.render(<App />, document.querySelector('#app'));