• 카테고리

    질문 & 답변
  • 세부 분야

    풀스택

  • 해결 여부

    미해결

댓글 삭제하기

21.11.02 16:18 작성 조회수 107

0

선생님 안녕하세요.
선생님 강의를 참고하여 댓글을 만들고 있습니다.
제가 만든것보다 깔끔하고 잘 적용이 되었습니다.
 
하지만 댓글 삭제를 하다보니
추가를 하면 생성된 데이터가 보이다 보니
response.data.result로 댓글이 바로 추가가 되는게 보이는데
삭제를 하면 댓글이 바로 삭제가 되는건 어떻게 하면 될까요?
를 이용하고 싶은데 잘 안되네요
props.refreshFunction

답변 1

답변을 작성해보세요.

0

안녕하세요 !!! 

먼저 디비에서 해당 댓글을 지우신 후에 
성공했다면  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)
}

이런식의 로직을 사용해주세요 !!!! 
감사합니다 ~~!