Share
Difference between React Pure Component vs React Component?
Question
- The biggest difference between React pure component vs a regular React component is that a React component doesn’t implement shouldComponentUpdate() by default. On the other hand, React pure component does implement shouldComponentUpdate() by default, and by performing a shallow comparison on React state and props values.
- When you use pure components, comparing states and props will consume memory storage.
- When a class component extends React.PureComponent base class then React treated the
- component as Pure component.
- The major difference between React.Component class and React.PureComponent is the implementation of shouldComponentUpdate().
- In React.Component shouldComponentUpdate() will always returns true on the other hand in React.PureComponent it will compare the current state and props with new state and props.
- As React.PureComponent implements shouldComponentUpdate() method for Pure component which will improve performance and optimize rendering. But the point here is that it is only doing the shallow comparison so if you have very complex nested object then it may give you false result
Leave an answer