0

I have an action 'set-style' sent to a reducer where i change a style object of a specified-by-key object in an array of objects, named layers.

The difficulty is - 'filterName' is used to receive the property name needed to be changed. If i use another property name it does behaves correct, but the 'filterName' variable does not function as a key.

export const set_stl = (val,filterName,chosenLayerId,chosenLayerIdx=0,layers) => {
const specLayer = layers[chosenLayerIdx];
const assignedSpecLayer = Object.assign({}, specLayer, {
    stl: {
        ...specLayer.stl,
        filterName: val
    }
});
const newLayers = layers;
    newLayers[chosenLayerIdx] = assignedSpecLayer;
return dispatch => {
    dispatch({
        type: SET_STL,
        payload: newLayers,
    })
}

};

nir segev
  • 338
  • 1
  • 4
  • 11

1 Answers1

1

You need to use [] for using the value of the filterName.

stl: {
    ...specLayer.stl,
    [filterName]: val
}
Suren Srapyan
  • 66,568
  • 14
  • 114
  • 112