我试图通过id更新我的redux商店中的评论,非常确定我做错了什么
case actionTypes.COMMENT_UPDATE:
console.log(action.comment.id)
console.log(action.comment.comment)
return update(state, {selectedPhoto: {comments: {[action.comment.id]: {comment: {$set: action.comment.comment}}}}
});
我的状态是这样的
答案 0 :(得分:0)
我使用以下代码,希望它可以帮助其他人
case actionTypes.COMMENT_UPDATE:
return {
...state,
selectedPhoto: {
...state.selectedPhoto,
comments: state.selectedPhoto.comments.map((comment) => {
return comment.id === action.comment.id ? { ...comment, comment: action.comment.comment } : comment
})
}
};