What is React.PureComponent?

React treats a component as a Pure component if it extends the React.PureComponent base class. The most significant distinction between React.PureComponent and React.Component is uses of shouldComponentUpdate.

In React.Component, the shouldComponentUpdate() method always returns true. The existing state and props are compared to the new state and props by React.PureComponent.

In React.PureComponent shouldComponentUpdate() only compares the object. It’s possible that false negatives for deeper differences will occur if these contain complex data structures.

Only extend React Pure Component when you get to have simple props and state, or use forceUpdate() when you know data has complex structures have changed.

In addition, React.PureComponents shouldComponentUpdate() skips the entire component subtree’s prop updates. Verify that all of the children’s components are also “pure.”

Being Tricky 😉

Leave a Reply

Your email address will not be published.