Skip to content

Instantly share code, notes, and snippets.

@nikolalsvk
Last active October 20, 2018 20:02
Show Gist options
  • Save nikolalsvk/9ddb6aa0e0895aa4f75535b16a5517cb to your computer and use it in GitHub Desktop.
Save nikolalsvk/9ddb6aa0e0895aa4f75535b16a5517cb to your computer and use it in GitHub Desktop.
import React, { Component } from "react";
class ButtonWithoutBind extends Component {
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 ButtonWithoutBind;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment