Skip to content

Instantly share code, notes, and snippets.

@nikolalsvk
Last active October 20, 2018 20:00
Show Gist options
  • Save nikolalsvk/23a0a8341940794659025a489fc98e9d to your computer and use it in GitHub Desktop.
Save nikolalsvk/23a0a8341940794659025a489fc98e9d to your computer and use it in GitHub Desktop.
import React, { Component } from "react";
class ButtonWithBind extends Component {
constructor() {
super();
this.state = { toggle: false };
}
toggleButton() {
this.setState(prevState => ({ toggle: !prevState.toggle }));
}
render() {
const toggle = this.state.toggle;
return (
<div>
<button onClick={this.toggleButton}>
{toggle ? "ON" : "OFF"}
</button>
</div>
);
}
}
export default ButtonWithBind;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment