React.Component vs React.PureComponent
Oct 25, 2020
I don’t know but many people say “React.PureComponent does shallow comparison over props and state inside shouldComponentUpdate()
.” But if you test yourself with code like this:
class Parent extends React.Component { <-- not PureComponent
render() {
return <div><Child say="hello" /></div>
}
}
We can see Child never re-render when parent does. So basically, React.Component is already doing shallow comparison over props. So I conclude, React.PureComponent does shallow comparison over state only inside shouldComponentUpdate().
Please correct me if I am wrong.
React.PureComponent is similar to React.Component. The difference between them is that React.Component doesn’t implement shouldComponentUpdate(), but React.PureComponent implements it — React Doc said.