**I’ve assigned to state2
the state
in order to avoid mutating the state array, and therefore making a _push _ on the state2
which is an array. But nothing worked. what to do Please??? state2
is supposed to be a copy of state
**
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) => {
let state2 = todos;
switch(action.type) {
case ADD_TO_DO:
// don't mutate state here or the tests will fail
{
state2.push(action.todo);
return state2;
}
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);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:62.0) Gecko/20100101 Firefox/62.0
.
Link to the challenge:
https://learn.freecodecamp.org/front-end-libraries/redux/never-mutate-state