Home > Tips & Tricks > What is React.PureComponent?

What is React.PureComponent?

React treats a component as a Pure component if it extends the React.PureComponent base class. The most significant distinction between React.PureComponent and React.Component is uses of shouldComponentUpdate.

In React.Component, the shouldComponentUpdate() method always returns true. The existing state and props are compared to the new state and props by React.PureComponent.

In React.PureComponent shouldComponentUpdate() only compares the object. It’s possible that false negatives for deeper differences will occur if these contain complex data structures.

Only extend React Pure Component when you get to have simple props and state, or use forceUpdate() when you know data has complex structures have changed.

In addition, React.PureComponents shouldComponentUpdate() skips the entire component subtree’s prop updates. Verify that all of the children’s components are also “pure.”

Being Tricky 😉

Photo of author

About Aman Mehra

Hey there! I'm Aman Mehra, a full-stack developer with over six years of hands-on experience in the industry. I've dedicated myself to mastering the ins and outs of PHP, WordPress, ReactJS, NodeJS, and AWS, so you can trust me to handle your web development needs with expertise and finesse. In 2021, I decided to share my knowledge and insights with the world by starting this blog. It's been an incredible journey so far, and I've had the opportunity to learn and grow alongside my readers. Whether you're a seasoned developer or just dipping your toes into the world of web development, I'm here to provide valuable content and solutions to help you succeed. So, stick around, explore the blog, and feel free to reach out if you have any questions or suggestions. Together, let's navigate the exciting world of web development!

Leave a Comment