Components re-renders when the parent render. Sometimes we may not need all the components get re rendered every time. As the program expanding these render can make some performance degrade.
PureComponent is a class component features. Functional component miss this feature.
So think about component that aware of the content, of course React has such One. A component extended from class PureComponent is called pure component.
class PureComp extends PureComponent {
render() {
console.log('*********Pure render*********');
return (
<div>
Pure Component {this.props.name}
</div>
)
}
}
export default PureComp
The class also implement shouldComponentUpdate lifecycle by perform shallow comparison on props and state.
The pure component only render when props name has changed. This is like someone keep tracking the changes for you.
I am really excited about this React feature