Tell us what’s happening:
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
return
default:
return state;
}
};
const removeItem = (index) => {
return {
type: ‘REMOVE_ITEM’,
index
}
}
const store = Redux.createStore(immutableReducer);
Your code so far
const immutableReducer = (state = [0,1,2,3,4,5], action) => {
switch(action.type) {
case 'REMOVE_ITEM':
const newState = state.filter( val => val !== action.index );
return newState;
default:
return state;
}
};
const removeItem = (index) => {
return {
type: 'REMOVE_ITEM',
index
}
}
const store = Redux.createStore(immutableReducer);
Your browser information:
User Agent is: Mozilla/5.0 (X11; CrOS x86_64 13099.72.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.94 Safari/537.36
.
Challenge: Remove an Item from an Array
Link to the challenge: