Created
August 11, 2017 09:32
-
-
Save erikras/7f1ebb674d99d2487431494d3241b5ac to your computer and use it in GitHub Desktop.
React Performance Anti-Pattern: Creating Functions in render() - solution2.js
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 MyCustomButton from './ui/MyCustomButton' | |
class MyClicker extends Component { | |
constructor() { | |
super() | |
this.state = { clicked: false } | |
} | |
handleClick = () => { | |
// "this" is the right instance of this component | |
this.setState({ clicked: true }) | |
} | |
render() { | |
return <div> | |
<MyCustomButton onClick={this.handleClick}> | |
Click Me | |
</MyCustomButton> | |
{this.state.clicked && <div>Nice work!</div>} | |
</div> | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment