강의

멘토링

커뮤니티

Inflearn Community Q&A

cjy15218897's profile image
cjy15218897

asked

Node and React series that you can learn by following - Creating a YouTube site

Create a comment function (4) ReplyComment

안녕하세요.

Written on

·

264

1

응용해서 비디오의 수정이나 삭제는 가능하게 만들었는데.. 댓글같은 경우에는 삭제시에 refreshfunction 기능을 어떻게 적용시켜야 할까요..ㅠ

reduxmongodbnodejsreact

Answer 3

2

John Ahn님의 프로필 이미지
John Ahn
Instructor

안녕하세요 

<span onClick={() => onDeleteComment(props.comment._id)}><Icon type="delete" /></span>

클릭하실때 comment의 아이디를 이용하셔서 

const onDeleteComment = (targetedCommentId) => {

let confirmRes = window.confirm('정말 이 글을 삭제하시길 원하시나요 ?');

if (confirmRes) {
const variables = {
commentId: targetedCommentId
}
Axios.post(``, variables)
.then(response => {
if (response.data.success) {
props.refreshDeleteFunction(response.data.deletedCommentId)
} else {
alert('댓글 지우기를 실패 했습니다.')
}
})
}

}

이런식으로 해주셔도 됩니다. ~ 

0

cjy15218897님의 프로필 이미지
cjy15218897
Questioner

DB에서 삭제도 되고 새로고침을 해야 댓글 삭제가 반영이 되어서 댓글 작성 처럼 새로고침 없이 바로바로 삭제될 수 있게 만들고싶습니다.ㅠ

0

cjy15218897님의 프로필 이미지
cjy15218897
Questioner

filer 를 이용하여서 선택된 댓글과 일치하지 않는 댓글을 렌더링하면 되는것 같은데 로직을 못짜겠어요..

cjy15218897's profile image
cjy15218897

asked

Ask a question