Guest User

Untitled

a guest
Feb 15th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. class App extends React.Component {
  2. constructor() {
  3. super()
  4. this.state = {
  5. isLoggedIn: false
  6. }
  7. this.handleClick = this.handleClick.bind(this)
  8. }
  9.  
  10. handleClick() {
  11. this.setState(prevState => {
  12. return {
  13. isLoggedIn: !prevState.isLoggedIn
  14. }
  15. })
  16. }
  17.  
  18. render() {
  19. return (
  20. <div>
  21. {this.state.isLoggedIn ? <h1>You are now logged in.</h1> : <h1>You are now logged out.</h1>}
  22. <button onClick={this.handleClick}>{this.state.isLoggedIn ? <h3>LOG OUT</h3> : <h3>LOG IN</h3>}</button>
  23. </div>
  24. )
  25. }
  26. }
Add Comment
Please, Sign In to add comment