const handleCommentSubmit = async (e) => {
e.preventDefault();
try {
const accessToken = getCookie("accessToken");
console.log(accessToken);
await instance.post(
`/api/comments`,
{
postId: id,
content: commentText
},
{
headers: {
Accept: "*/*",
Authorization: `${accessToken}`,
},
}
)
setCommentText('');
} catch (error) {
console.log('댓글 작성 실패', error);
}
}
-----------------------댓글 추가 기능----------------------------
const accessToken = getCookie("accessToken");
const addCommentMutation = useMutation(
(commentText) =>
instance.post(
`/api/comments`,
{
postId: id,
content: commentText,
},
{
headers: {
Accept: '*/*',
Authorization: `${accessToken}`,
},
}
),
{
onError: (error) => {
console.log('댓글 작성 실패', error);
},
onSettled: () => {
queryClient.invalidateQueries('comments');
},
}
);
const handleCommentSubmit = async (e) => {
e.preventDefault();
try {
await addCommentMutation.mutateAsync(commentText);
setCommentText('');
} catch (error) {
console.log('댓글 작성 실패', error);
}
};