我有注释组件,用于呈现注释。我可以回复评论并将其存储为子项(parentId!= null和parentId = commentId); 在我的化简器中,我想考虑这一点并按层次结构显示注释,例如
到目前为止,我做了如下操作,但是它不起作用:
if (action.comment.parentId) {
let index = state.requestComments.findIndex(item =>
item.id === action.comment.parentId);
return {
...state,
requestComments: [...state.requestComments.slice(
0, index),
action.comment,
...state.requestComments.slice(index)
],
error: null,
isCommentLoading: false
};
} else {
return {
...state,
requestComments: [...state.requestComments,
action.comment],
error: null,
isCommentLoading: false
};
}