인프런 커뮤니티 질문&답변
댓글 삭제하기
작성
·
195
답변 1
0
John Ahn
지식공유자
안녕하세요 !!!
먼저 디비에서 해당 댓글을 지우신 후에
성공했다면 State에서도 지워줘야하는데 그 때
const updateDeleteComment = (deletedCommentId) => {
//We can just refetch all of the revised comment datas from DB
//But it is better just to change some parts that has changed from delete function
let targetedCommentIndex;
let newCommentList = [...CommentLists]
CommentLists.map((comment, index) => {
if (comment._id === deletedCommentId) {
targetedCommentIndex = index
}
return null;
})
newCommentList.splice(targetedCommentIndex, 1);
setCommentLists(newCommentList)
}
이런식의 로직을 사용해주세요 !!!!
감사합니다 ~~!





