Now we’ll change the Square’s render
method to display the current state’s value when clicked:
- class Square extends React.Component {
- constructor(props) {
- super(props);
- this.state = {
- value: null,
- };
- }
- render() {
- return (
- <button className="square"
- onClick={() => this.setState({value: 'x'}) }
- >
- {this.state.value}
- </button>
- );
- }
- }
-
- export default Square;