I have the following state
const initialState = {
photos: [],
selectedPhoto:{},
photosTeamId:'',
photosProjectId:''
};
photos is an array which has a photo object and inside the photo object, there is an array of comments. I'm trying to find the correct photo then find the correct comment and update that one.
Here is my code
case actionTypes.COMMENT_UPDATED_TO_PHOTOS:
console.log(action.data)
return {
...state,
photos: state.photos.map((photo) => {
photo.id === action.data.selectedPhotoId ? {
comments: photo.comments.map((comment) => {
console.log(comment)
return comment.id === action.data.commentId ? { ...comment, comment: action.data.fullComment } : comment
})
} : photo
})
}