i have state, part of array called 'numbers'. 1 of actions change state in following way: odd numbers should changed zero, numbers should kept. 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 ? : 0))];
this 1 produces error: unexpected token, expected , ... , 'return' line being indicated location of error. please advise
looking @ code you've shared:
case turn_even: return [...state, numbers: state.numbers.map( (i) => (i % 2 === 0 ? : 0))];
it looks state of reducer has different properties, 1 of them being numbers
.
maybe wanted instead:
case turn_even: return object.assign( {}, state, { numbers: state.numbers.map(i => (i % 2 === 0 ? : 0)) } );
i haven't seen rest of reducer, maybe don't have enough context encourage try make reducer each 1 of properties of state, 1 of them numbers
, use combinereducers
combine them one. small functions easier deal with.
if did that, have reducer 1 numbers:
const initialstate = []; const numbersreducer = (state = initialstate, action) => { swicth (action.type) { case turn_even: return state.map(i => (i % 2 === 0 ? : 0)); // other action types here... default: return state; } }
Comments
Post a Comment