Tell us what’s happening:
Hello everyone!
The lesson states that every time we return a state, it’s another version of the state rather than a modified state. How do you I see different states? Store.dispatch(addToDo("Learn React)) & console.log(todos) returns the old state without “Learn React” in the array.
Thanks!
Your code so far
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:
// don't mutate state here or the tests will fail
return todos.concat(action.todo)
default:
return state;
}
};
// an example todo argument would be 'Learn React',
const addToDo = (todo) => {
return {
type: ADD_TO_DO,
todo
}
}
const store = Redux.createStore(immutableReducer);
store.dispatch(addToDo("Learn React"))
console.log(todos)
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36
.
Link to the challenge: