Redux: Use the Spread Operator on Arrays

Redux: Use the Spread Operator on Arrays
0.0 0

#1

I 'm unable to figure out why my code is not working, please help ,

const immutableReducer = (state = ['Do not mutate state!'], action) => {
  switch(action.type) {
    case 'ADD_TO_DO':
      // don't mutate state here or the tests will fail
    return [... state, action.todo];
    default:
      return state;
  }
};

const addToDo = (todo) => {
  return {
    type: 'ADD_TO_DO',
    todo: todo
  }
}

const store = Redux.createStore(immutableReducer);

https://learn.freecodecamp.org/front-end-libraries/redux/use-the-spread-operator-on-arrays


#2

You should not have a space between the spread operator and the array named state.


#3

i think you have a space after the three dots? (…state) not (… state) The dots should not have a space after them.


#4

Thank you .
How you guys can find out these errors not us? are you using any software ?


#5

yup. the ‘software’ is our experience… :slight_smile:
When you make mistakes over and over, you learn.