How to delete an item from Redux state with JavaScript?

To delete an item from Redux state with JavaScript, we can use the array filter method.

For instance, we write

export const commentList = (state, action) => {
  switch (action.type) {
    //...
    case "DELETE_COMMENT":
      return state.filter(({ id }) => id !== action.data);
    //...
  }
};

to call state.filter to return an array without the object with the id property equal the action.data property.

The returned array will be the new value of the state.