Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

In Vue3 changing root state stopped working

My mutations which changes root state stopped working

 SET_STATE(state, payload) {
    state = { ...state, ...payload };
 }

But changing inner value is working

SET_INNER_STATE(state, payload) {
   state.inner = payload;
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

This state = ... changes state local variable (parameter), it cannot affect anything that happens outside this function.

{ ...state, ...payload } shouldn’t be done in Vue because it doesn’t force immutable state the same way as React.

Initial state should be generally set on store initialization. If it should occur later for some reason, it should be merged to existing state object. Shallow merge can be:

Object.assign(state, payload);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading