Z
Z
zhodino2018-09-07 15:45:33
redux
zhodino, 2018-09-07 15:45:33

Is it possible to change an object property dynamically in Redux?

case SET_VALUE:
        return {
            data: {
              ...state.data,
              action.payload.type: action.payload.value,
            }
          };

We have action. Is it possible to change the property of an object that is in the state, and select this property depending on the action that comes
I mean this part
action.payload.type: action.payload.value,

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Afanasy Zakharov, 2018-09-07
@zhodino

of course, that's how they usually do it.
just do it like this

data: {
              ...state.data,
              [action.payload.type]: action.payload.value,
            }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question