DEV Community

Discussion on: What the benefit immutable on the state management?

Collapse
 
patryktech profile image
Patryk

I use Vue, not React, but one more reason to use immutable state is to prevent unexpected side-effects.

If you have many computed properties, and you change the base object that a number of them depend on in one component, it may affect other components in ways you didn't expect. I believe Vue raises an error if you try to modify Vuex state outside of mutations.

If your component modifies the state only in its own copy of an object, the changes are localized and there are no far-reaching side effects, which helps prevent some bugs.

Collapse
 
malloc007 profile image
Ryota Murakami

Thank you for your Vue perspective, my last vue experience is at the 2015 DX
So I'm glad to know 2020's Vue Dev perspective 🤩

And I agree with last your last paragraph, thank you! 😄