I have a state, part of which is an array called 'numbers'. One of the actions is to change the state in the following way: all the odd numbers should be changed to zero, all the even numbers should be kept. For example:
previous state
[9, 3, 2, 6, 8]
action
new state
[0, 0, 2, 6, 8]
action creator:
export const turnEven = () => {
return {
type: TURN_EVEN
};
};
reducer:
case TURN_EVEN:
return [...state, numbers: state.numbers.map(
(i) => (i % 2 === 0 ? i : 0))];
This one produces an error: unexpected token, expected , ... and the 'return' line is being indicated as the location of the error. Please advise