DEV Community

Discussion on: ReactJS -- If it is setting a state with the same value, will the component be re-rendered?

Collapse
 
sunflower profile image
sunflowerseed

can you change the class component so that it behaves like useState(0)?

Collapse
 
wolverineks profile image
Kevin Sullivan • Edited

If you extend the class component from React.PureComponent it will do a shallow comparison on props and state to determine if it should rerender.

That being said, doing this is usually slower than allowing the component to rerender.