Hi, this code doesn’t pass the test and I dont know why! The error is “Dispatching an action of type ADD_TO_DO on the Redux store should add a todo item and should NOT mutate state” But I dont get it, cause my code meets the requirement. Pls, help me
const ADD_TO_DO = 'ADD_TO_DO';
// A list of strings representing tasks to do:
const todos = [
'Go to the store',
'Clean the house',
'Cook dinner',
'Learn to code',
];
const immutableReducer = (state = todos, action) => {
switch(action.type) {
case ADD_TO_DO:
let newArr = state.slice();
newArr.splice(newArr.length, 0, action.todo);
console.log(newArr);
return newArr;
default:
return state;
}
};
// an example todo argument would be 'Learn React',
const addToDo = (todo) => {
return {
type: ADD_TO_DO,
todo: 'Learn React'
}
}
const store = Redux.createStore(immutableReducer);
Also, due to es6 destructuring, you don’t even need to assign the todo variable to the todo key, as they are the same. You can just leave the object as:
We usually try to avoid giving the answer but prefer to lead them in the right direction. And remember that if you do post an answer, to wrap it in [spoiler] tags. Also, instead of <code><pre> you can just use three backticks on the line before and three backticks on the line after.