-
Notifications
You must be signed in to change notification settings - Fork 49.9k
Closed
Description
class App extends React.PureComponent {
state={
ele: {a:'1'}
}
trigger=()=>{
console.log('click')
this.setState({ele: {a:'1'}})
}
render() {
console.log('render')
return (
<div onClick={this.trigger}>click here to trigger setState</div>
);
}
}
A simple demo shows that click event triggers render every time.
demo
However, according to source code, React.PureComponent’s shouldComponentUpdate() shallowly compares the objects like following, the click event shouldn't trigger render.
Performs equality by iterating through keys on an object and returning false when any key has values which are not strictly equal between the arguments. Returns true when the values of all keys are strictly equal.
Metadata
Metadata
Assignees
Labels
No labels