Passing data to commit is breaking state update

vuex

#1

i have reusable component that will update deferent db and state object record,

       REPLACE_COLOR : (state, [color, index]) => {

            state.widgets[index].bg_color = color;

            Event.$emit('requestAlertSuccess');

        },

the component is updating the state correctly but now i need to make i dynamic in way to change which state object it should update by passing the name argument (name might be bg_image, bg_color, bg_gradient ) like this

       REPLACE_COLOR : (state, [color, fieldname, index]) => { // fieldname contains correct data

            state.widgets[index].fieldname = color;

            Event.$emit('requestAlertSuccess');

        },

unfortunately after the update the state stop getting updated, so how can i make this process work.

is there is a better way to do this.


#2
state.widgets[index][fieldname] = color;