yoneda
2/17/2019 - 4:27 AM

react-class-component-focus-on-state

class Test extends React.Component{
  constructor(){
    super();
    this.state = {toggle:false}
    this.updateToggle = this.updateToggle.bind(this);
  }
  
  updateToggle(flag){
    this.setState({toggle:flag});
  }

  render(){
    return(
      <div>
        <button onClick={()=>this.updateToggle(!this.state.toggle)}>button</button>
        <p>{this.state.toggle ? "on" : "off" }</p>
      </div>
    )
  }
}