Created
February 19, 2019 20:18
-
-
Save stolinski/5362d2914bc6461e2a8d06595400bd37 to your computer and use it in GitHub Desktop.
Refactor For Hooks Course
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from "react"; | |
export default class Refactor extends Component { | |
state = { | |
isToggled: false | |
}; | |
toggle = () => { | |
this.setState(state => { | |
return { isToggled: !state.isToggled }; | |
}); | |
}; | |
render() { | |
return ( | |
<div> | |
<button onClick={this.toggle}>Toggle</button> | |
{this.state.isToggled && <h2>Hello!</h2>} | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment