DEV Community

Discussion on: Don't over useState

Collapse
 
varuns924 profile image
Varun S

If you just store it in a const and remove any updates to const, how does it update categories? Or is it because arrays are objects?

Collapse
 
tkdodo profile image
Dominik D

categories is created new in every render cycle by computeCategories. After that, we don’t update it at all. Every time data changes, React will re-render and thus call computeCategories again - giving us a new Array of categories.

Collapse
 
varuns924 profile image
Varun S

Oh I didn't know React rerenders the entire component for a state change. Thanks for the explanation!