더북(TheBook)

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,
  });
};

(...)

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