1 回答

TA貢獻(xiàn)1966條經(jīng)驗(yàn) 獲得超4個(gè)贊
嘗試這個(gè)
function submitComment() {
let request = {
body: comment,
code_id: props.id,
line_number: props.lineNumber,
parent_comment_id: props.parentCommentId
};
fetch('/api/comment/add',
{
method: 'POST',
body: JSON.stringify(request)
}
).then(response => response.json())
.then(data => {
if (data.success === 1) {
props.updateComments();
resetCommentInput();
// Run resetCommentInput before props.toggleReplyBoxVisibility
if (props.parentCommentId) {
props.toggleReplyBoxVisibility(props.commentIndex);
}
}
});
}
您應(yīng)該在卸載之前更新組件狀態(tài)
添加回答
舉報(bào)