Hello So I want to give my reducer the ability to remove an item in an array of a property. I am working with a state of users that looks like this.
users = {
'testUser1:{
id:'',
name:'',
favorites:['oranges','apples'],
lists:{
myList:[]
}
},
}
I want to be able to delete items from the favorites property in my reducer.
here is my reducer so far
function usersReducer(state={},action){
switch(action.type){
case RECEIVE_USERS:
return{
...state,
...action.users,
}
case ADD_FAVORITE:
return{
...state,
[action.authedUser]:{
...state[action.authedUser],
favorites:
state[action.authedUser].favorites.concat([action.favorite])
}
}
case DELETE_FAVORITE:
/*const newArray = Object.values(action.authedUser.favorites).filter((item)=>
item !== 'oranges'
) */
}
}
}