3 ms·
Why isn't PureComponent just default?
by Kiro 10y ago
Why isn't PureComponent just default?
- acemarke 10y agoA few reasons: - PureComponent was only added relatively recently. - While shallow equality comparisons are relatively fast compared to deep equality comparisons, they still burn CPU. There's also a number of reasons why props could have changed, such as object literals being declared in the parent's `render` method, or the component receiving other components via `props.children`. In those cases, the "pure" comparison will fail every time, and be useless. - There is no "default" per se. Application components explicitly extend a React component base class - either React.Component, or React.PureComponent.
- vinnymac 10y agoIt is not a bullet proof solution. It has its use cases, but a couple pitfalls as well. Using PureComponent as a parent to many Component classes is generally not a good idea. If a child depends on a change from `this.context` it will not re-render unless the PureComponent declares `contextTypes`. https://github.com/facebook/react/issues/2517 https://github.com/facebook/react/issues/2517