Skip to content

Instantly share code, notes, and snippets.

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