Hey guys I have a question for this challenge. I can’t seem to pass the last test which requires the state to not be mutated. However I’m printing the state and arr values in my local IDE and the state prints its original values and does not appear to mutate. What am I doing wrong here?
This is my code
const immutableReducer = (state = [0,1,2,3,4,5], action) => {
switch(action.type) {
case 'REMOVE_ITEM':
// don't mutate state here or the tests will fail
let arr =[...state].filter(x =>x !== action.index);
return arr;
default:
return state;
}
};
const removeItem = (index) => {
return {
type: 'REMOVE_ITEM',
index
}
}
const store = Redux.createStore(immutableReducer);
Thanks guys!
challenge link https://www.freecodecamp.org/learn/front-end-libraries/redux/remove-an-item-from-an-array