Guest User

Untitled

a guest
Dec 13th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 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. this.toggleButton = this.toggleButton.bind(this)
  10. }
  11.  
  12. render() {
  13. const toggle = this.state.toggle;
  14.  
  15. return (
  16. <div>
  17. <button onClick={this.toggleButton}>
  18. {toggle ? "ON" : "OFF"}
  19. </button>
  20. </div>
  21. )
  22. }
  23.  
  24. toggleButton() {
  25. this.setState({ toggle: !this.state.toggle });
  26. }
  27. }
  28.  
  29. export default ButtonWithBind;
Add Comment
Please, Sign In to add comment