Skip to content

Instantly share code, notes, and snippets.

@mrcthms
Created September 27, 2018 17:46
Show Gist options
  • Save mrcthms/d8978aa84771dd0ed543321dc8b61271 to your computer and use it in GitHub Desktop.
Save mrcthms/d8978aa84771dd0ed543321dc8b61271 to your computer and use it in GitHub Desktop.
class Parent extends Component {
state = {
counter: 0
}
handleClick = () => this.setState({ counter: this.state.counter + 1 })
render() {
return (
<div>
<p onClick={this.handleClick}>{this.state.counter}</p>
<Child />
</div>
)
}
}
class Child extends Component {
render() {
return <div>I will re-render every time the counter changes, even though I do not change myself.</div>
}
}
class PureChild extends PureComponent {
render() {
return <div>I will only ever be rendered once.</div>
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment