: postId를 작성되어진 article 하나의 id인 'ceda'로 고정시켰다.
{
"articles": [
{
"id": "ceda",
"category": "모각코",
"title": "afds",
"content": "<p>adsgsdg</p>",
"author_id": "",
"date": "2024-09-14T20:57:19.686Z",
"cafe_address": "강남",
"region": "",
"cafe_name": "우리집"
}
],
"comments": [
{
"id": "30df",
"text": "댓글 1을 입력했습니다.",
"postId": "ceda"
},
{
"id": "b7d6",
"text": "댓글 2를 입력했습니다.",
"postId": "ceda"
}
]
}
zustand를 댓글 기능부분에서도 사용해야 하는 줄 알았는데 로그인/회원가입 기능에서만 사용하면 된다고 하여 작성한 코드를 지웠다.
기존에 알고 있던 방식은
button 태그에 onClick으로 함수를 선언하고, 선언할 때 mutation.mutate({text, postId})
이렇게 주는 걸로 알고 있었다.
추가, 수정, 삭제에 대한 useMutation에 mutate의 이름을 각각 지정 후, handleAddComment, handleEditComment, handleDeleteComment 함수를 만들어 버튼의 onClick에서 함수를 실행시켜 줬는데 이 때 내가 작성한 처음 코드는 addComment.mutate()
, editComment.mutate()
, deleteComment.mutate()
라고 적어줬다.
실행이 제대로 되지않아 수정한 코드는 'mutation.mutate' 이 부분 전체를 mutate의 alias(별칭)이었다.
addComment()
, editComment()
, deleteComment()
이렇게 작성해야 했다.