Guest User

Untitled

a guest
Dec 13th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. import React, { Component } from "react";
  2.  
  3. class ButtonWithBind extends Component {
  4. constructor() {
  5. super();
  6.  
  7. this.state = { toggle: false };
  8. }
  9.  
  10. render() {
  11. const toggle = this.state.toggle;
  12.  
  13. return (
  14. <div>
  15. <button onClick={this.toggleButton}>
  16. {toggle ? "ON" : "OFF"}
  17. </button>
  18. </div>
  19. )
  20. }
  21.  
  22. toggleButton() {
  23. this.setState({ toggle: !this.state.toggle });
  24. }
  25. }
  26.  
  27. export default ButtonWithBind;
Add Comment
Please, Sign In to add comment