I have a initial state variable that is an array of objects and want to filter / delete multiple objects given in another array containing the id's of the objects to be filtered in the payload
const initialState = {
data: [
{
name: "apple",
id: 1
},
{
name: "orange",
id: 2
},
{
name: "broccoli",
id: 3
},
{
name: "spinach",
id: 4
},
]
}
export default (state = initialState, { type, payload }) => {
switch (type) {
case FILTER_ITEMS:
//filteredArray =
return {
...state,
data: filteredArray
}
}
I want to filter items from the initialState that do not have the id's as given in the array inside the payload
payload = {
excludeIds = [2,4]
}
So after the reducer runs the initialState should be changed to:
state = {
data: [
{
name: "apple",
id: 1
},
{
name: "broccoli",
id: 3
},
]
}