Passing data to commit is breaking state update



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

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

            state.widgets[index].bg_color = color;



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;



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.

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