Bradley Bradley - 1 month ago 18x
React JSX Question

Delete an item from Redux state

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 via
into the reducer.

I'm wondering how I can match the
with one of the ID's within the Redux state and then remove that object from the array? I am also wondering the best way to then set the new state after the individual object has been removed?

Please see the code below:

export const commentList = (state, action) => {
switch (action.type) {
let newComment = { comment:, id: +new Date };
return state.concat([newComment]);
let commentId =;

return state || [];


Just filter the comments:

  const commentId =;
  return state.filter(comment => !== commentId);

This way you won't mutate the original state array, but return a new array without the element, which had the id commentId.