I have the following state in my redux store, it's photos which has an array of objects
Each object is different, I need to be able to find the object with the filename and remove the entire array item I have tried with index and the following but not really working
case actionTypes.PHOTO_DELETE:
// return state.filter((photo) => photo.filename !== action.data)
return { photos: state.photos.filter(photo =>
photo.filename !== action.data
)}
// let index = state.photos.findIndex((photo) => photo.fillname === action.data);
//console.log(index)
/*
var index = _.findIndex(action.data, function(photos) {
return photos.photos == action.data
})
*/
//return update(state, {photoGroups: {$splice: [[index]]}});
Filter the photos array by checking if the object with specified filename does not exist in the inner array. If it doesn't then findIndex() === -1
.
return {
photos: state.photos.filter(photo =>
photo.findIndex(object => object.filename === action.data) === -1
)
}