Answer the question
In order to leave comments, you need to log in
How to immutably remove a property from an array in a reducer?
There is an initial state:
const initialState = {
products: [
{ id: 5 },
{ id: 7 }
]
}
function (state = initialState, action) {
case REMOVE_PRODUCT_CART:
return {
...state,
products: state.products.filter(item => item.id !== action.payload)
}
}
function removeItem(array, action) {
return array.filter( (item, index) => index !== action.index);
}
Answer the question
In order to leave comments, you need to log in
Below is an example solution, but how immutable is it?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question