DEV Community

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

Collapse
 
dance2die profile image
Sung M. Kim • Edited

Nice demos there~

It's a confusing concept well-demonstrated.

For Class component version this.setState({ count: value }); you are changing the "reference". For the Function Component, you are changing the primitive, thus the component doesn't re-render.

React re-renders as states change. States change when a "reference" change. Primitive values are stored in stack. This leads understanding of JS.

For more info on how FC & CC differ check out

overreacted.io/how-are-function-co...

Collapse
 
nigel447 profile image
nigel447

thanks Sung really helpful article

Collapse
 
dance2die profile image
Sung M. Kim • Edited

You're welcome :)

Dan's article's are long but well written and thorough.