Skip to content

Instantly share code, notes, and snippets.

@erikras
Last active August 11, 2017 09:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erikras/8f628b678064dde4290c0c8f0ff229c6 to your computer and use it in GitHub Desktop.
Save erikras/8f628b678064dde4290c0c8f0ff229c6 to your computer and use it in GitHub Desktop.
React Performance Anti-Pattern: Creating Functions in render() - problem.js
import MyCustomButton from './ui/MyCustomButton'
class MyClicker extends Component {
constructor() {
super()
this.state = { clicked: false }
}
render() {
return <div>
<MyCustomButton onClick={() => this.setState({ clicked:true })}>
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