Continuing the discussion from freeCodeCamp Challenge Guide: Never Mutate State:
why is the “todo” inside the return object not in a key value pair?
const addToDo = todo => {
return {
type: ADD_TO_DO,
todo
};
};
and also, why doesn’t return state.slice().push(action.todo)
work here ?
const immutableReducer = (state = todos, action) => {
switch (action.type) {
case ADD_TO_DO:
// don't mutate state here or the tests will fail
return state.concat(action.todo);
// or return [...state, action.todo]
default:
return state;
}
};