4 ms·
There's a default shouldComponentUpdate implementation in the React.Component. It does a shallow compare of state and props. When you define shouldComponentUp
by jefffan241 9y ago
There's a default shouldComponentUpdate implementation in the React.Component. It does a shallow compare of state and props. When you define shouldComponentUpdate you are just overriding that implementation. So it's always called, its just you don't need to always define it.
- haukur 9y agoThe shallow check is on React.PureComponent. shouldComponentUpdate just returns true by default in React.Component components. See here for details: https://facebook.github.io/react/docs/react-api.html#react.purecomponent https://facebook.github.io/react/docs/react-api.html#react.p...
- deleted 9y ago[deleted]
- danmaz74 9y agoFrom the React website: "When a component's props or state change, React decides whether an actual DOM update is necessary by comparing the newly returned element with the previously rendered one." My point is that if a component doesn't receive a setState or new props it just doesn't start the rendering cycle at all (AFAIK), so shouldComponentUpdate doesn't get called at all.