Pure Components

A Pure Component in React is a component that only re-renders when its props or state change.

🧠 Why Pure Components are Useful:

  • Optimized Performance: Pure components avoid unnecessary re-renders by implementing shallow comparison on props and state.

  • Automatic Optimization: React performs a shallow comparison of props and state automatically, ensuring that the component only re-renders when there are actual changes.

Example of a Pure Component:

javascript
1class MyComponent extends React.PureComponent { 2 render() { 3 return <div>{this.props.value}</div>; 4 } 5}

In short:

Pure components are efficient because they only re-render when there is a change in their props or state, optimizing performance in React applications.