in React JS by

What is PureComponent? When to use PureComponent over Component

▼ Show 1 Answer

0 votes

PureComponent is exactly the same as Component except that it handles the shouldComponentUpdate method for us. When props or state changes, PureComponent will do a shallow comparison on both props and stateComponent on the other hand won't compare current props and state to next out of the box. Thus, the component will re-render by default whenever shouldComponentUpdate is called.

When comparing previous props and state to next, a shallow comparison will check that primitives have the same value (eg, 1 equals 1 or that true equals true) and that the references are the same between more complex javascript values like objects and arrays.

It is good to prefer PureComponent over Component whenever we never mutate our objects.

React JS
Learn More with Madanswer

Related questions

0 votes
asked Jul 2, 2019 in React JS by Venkatshastri