Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, { Component } from "react";
- class ButtonWithBind extends Component {
- constructor() {
- super();
- this.state = { toggle: false };
- }
- render() {
- const toggle = this.state.toggle;
- return (
- <div>
- <button onClick={this.toggleButton}>
- {toggle ? "ON" : "OFF"}
- </button>
- </div>
- )
- }
- toggleButton() {
- this.setState({ toggle: !this.state.toggle });
- }
- }
- export default ButtonWithBind;
Add Comment
Please, Sign In to add comment