Categories

Jul 2, 2019 in React JS

Q:

What is PureComponent? When to use PureComponent over Component

1 Answer

Jul 2, 2019

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.

Click here to read more about React JS
Click here to read more about Insurance

Related questions

Madanswer
Jul 2, 2019 in React JS
Jul 2, 2019 in React JS
Jul 2, 2019 in React JS
...