Redux: Use the Spread Operator on Arrays

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

1 Like

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

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

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

4 Likes