score:2

Accepted answer

Try changing your reducer to be:

case "ADD_REVIEW_ITEM":
      return state.map((data) => {
        if (data.id === action.payload.selectedDataId) {
          return {
            ...data,
            listOfReview: [...data.listOfReview, action.payload.newReview]
          };
        }
        return data;
      });

Currently, you are mutating the state variable and pushing in an array which can lead to side-effect.


Related Query

More Query from same tag