Use the Spread Operator on Arrays NEW

Tell us what’s happening:

Why in addToDo function where todo is arg we return object like that

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

and not this way:

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

isnt todo an argument that needs to be returned as object parameter ?

Your code so far


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
  }
}

const store = Redux.createStore(immutableReducer);

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:67.0) Gecko/20100101 Firefox/67.0.

Link to the challenge:

1 Like

It’s just a shorthand available in JS. If you put a variable name where a key-value pair would normally go, JS engine will automatically make the pair for you.

2 Likes