What is the proper way to reset an array in an NgRx reducer?
I am using NgRx to create a basic reducer that includes an empty array called myArray
in the initial state:
import * as MyActions from './my.actions';
const myState = {
myValue: 'foo',
myArray: []
}
In this scenario, I have an action named ARRAY_RESET
which resets myArray
to an empty array like this:
export function myReducer(
state = myState,
action: MyActions.MyActionTypes
) {
switch(action.type) {
case MyActions.ARRAY_RESET:
return {
...state,
myArray: [] <---- I RETURN AN EMPTY ARRAY
};
case MyActions.ARRAY_PUSH:
return {
...state,
myArray: [...state.myArray, action.payload]
};
default:
return state;
}
}
Would you consider this method to be correct?