I\'m wondering if you could help me with this problem if possible. I am trying to delete an item from the Redux state. I have passed in the ID of the item that the user clicks v
Just filter the comments:
case 'DELETE_COMMENT':
const commentId = action.data;
return state.filter(comment => comment.id !== commentId);
This way you won't mutate the original state
array, but return a new array without the element, which had the id commentId
.
To be more concise:
case 'DELETE_COMMENT':
return state.filter(({ id }) => id !== action.data);