redux存储中的React-Native更新特定项

时间:2017-10-31 04:46:24

标签: reactjs react-native redux react-redux

我试图通过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}}}}
            });
我的状态是这样的 enter image description here

1 个答案:

答案 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
                    })
                }
            };