Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class App extends React.Component {
- constructor() {
- super()
- this.state = {
- isLoggedIn: false
- }
- this.handleClick = this.handleClick.bind(this)
- }
- handleClick() {
- this.setState(prevState => {
- return {
- isLoggedIn: !prevState.isLoggedIn
- }
- })
- }
- render() {
- return (
- <div>
- {this.state.isLoggedIn ? <h1>You are now logged in.</h1> : <h1>You are now logged out.</h1>}
- <button onClick={this.handleClick}>{this.state.isLoggedIn ? <h3>LOG OUT</h3> : <h3>LOG IN</h3>}</button>
- </div>
- )
- }
- }
Add Comment
Please, Sign In to add comment