Are you first timer at lazacode.org? Why not join us and start exchange your programming knowledge with everyone. Register today!

React - click to change render method to display state's value

0 votes
16 views
added Mar 8 in React by LC Marshal Captain (20,510 points)

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;

 

Please log in or register to response this reference.

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...