Skip to content

Instantly share code, notes, and snippets.

@yoneda
Last active July 17, 2019 15:45
Show Gist options
  • Save yoneda/edea4e68c7b64042586062c29cc0b805 to your computer and use it in GitHub Desktop.
Save yoneda/edea4e68c7b64042586062c29cc0b805 to your computer and use it in GitHub Desktop.
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>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment