The initial state looks like this:
const INITIAL_STATE = {
myArray: []
};
Now in my reducer, I want to append a new object to the existing array. I came up with something like this but it doesn't work as expected.
case ADD_TO_ARRAY:
return {
...state,
myArray: [...state[ { action.payload.key: action.payload.value} ]]
};
Note: I want to create a new object, in line, using the key and value passed in the action payload.