Pure Component
Pure Components are a subclass of class components provided by React. They come with a built-in optimization to prevent unnecessary re-renders. Pure Components implement a shouldComponentUpdate
method, which performs a shallow comparison of the component’s props and state. If the new props and state are shallowly equal to the previous props and state, the component won’t re-render, thereby optimizing performance.
Syntax:
// Syntax for Pure component
import React, { PureComponent } from 'react';
class YourComponent extends PureComponent {
render() {
return
<div>
Your Creativity goes here......
</div>;
}
}
How does a Pure Component Differ from a Regular Component ?
In React, components are the building blocks of user interfaces. They encapsulate the UI logic and render the UI elements based on the input data. React offers different types of components, including regular components and Pure Components.
Table of Content
- Components in React
- Regular Components
- Benefits of Regular Components
- When to use Regular Components
- Pure Component
- Benefits of Pure Components
- When to use Pure Components
- Difference
- Conclusion
Contact Us