3 ms·
By default, React doesn’t check if individual props are equal. This is for two reasons: 1. We support using mutable objects in props. Even if a prop is referen
by sophiebits 8y ago
By default, React doesn’t check if individual props are equal. This is for two reasons:
1. We support using mutable objects in props. Even if a prop is reference identical to the last render, the component might be reading some property of it that has changed.
2. Checking equality of props takes time. In the (common) case where a parent rerenders and it’s children need to change in response, any time we spend comparing will be extra overhead on top of the actual render cost. Often rerendering is fast anyway and adding more comparisons only makes it slower.
Because of these, we don’t do these checks by default. Instead, we recommend adding memo/PureComponent/shouldComponentUpdate in places where you know it will make a difference.
- mcintyre1994 8y agoThanks for this explanation, that makes a lot of sense! :)
- sophiebits 8y ago(typo: its children need to change)