screens/ArticleScreen.tsx

    import {deleteComment, getComments, modifyComment} from '../api/comments';
    
    (...)
    
    const {mutate: modify} = useMutation(modifyComment, {
      onSuccess: comment => {
        queryClient.setQueryData<Comment[]>(['comments', id], comments =>
          comments
            ? comments.map(c => (c.id === selectedCommentId ? comment : c))
            : [],
        );
      },
    });
    
    (...)
    
    const onSubmitModify = (message: string) => {
      setModifying(false);
      modify({
        id: selectedCommentId!,
        articleId: id,
        message,
      });
    };
    
    (...)

    댓글 수정 기능을 모두 구현했습니다! 댓글을 수정해보세요. 수정한 댓글이 댓글 목록에 잘 반영됐나요?

    신간 소식 구독하기
    뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.