What are pure components?
Pure Component is a React class component that automatically implements
shouldComponentUpdate with a shallow prop and state comparison.
- Benefit: It prevents unnecessary re-renders by performing a shallow comparison of
props and state.
Example:
class MyComponent extends React.PureComponent {
render() {
return <div>{this.props.name}</div>;
}
}
Pure components are a good choice when you know that your component only depends on
props and state and you want to avoid unnecessary updates.