From 2487b4f8b795d0b225c2929dfd6c39f55b106057 Mon Sep 17 00:00:00 2001 From: Lee jin <83453646+j-nary@users.noreply.github.com> Date: Wed, 9 Oct 2024 22:02:15 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20useMutationPostLike=20type=EC=97=90?= =?UTF-8?q?=EC=84=9C=20data=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/post/hooks.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/api/post/hooks.ts b/src/api/post/hooks.ts index 82e0cb1a..cbbfddf4 100644 --- a/src/api/post/hooks.ts +++ b/src/api/post/hooks.ts @@ -70,9 +70,7 @@ export const useQueryGetPost = (postId: string) => { }); }; -type postType = { - data: paths['/post/v2/{postId}']['get']['responses']['200']['content']['application/json;charset=UTF-8']; -}; +type postType = paths['/post/v2/{postId}']['get']['responses']['200']['content']['application/json;charset=UTF-8']; export const useMutationPostLike = (queryId: string) => { const queryClient = useQueryClient(); @@ -83,13 +81,13 @@ export const useMutationPostLike = (queryId: string) => { onMutate: async () => { const previousPost = queryClient.getQueryData(['getPost', queryId]) as postType; - const newLikeCount = previousPost.data.isLiked - ? previousPost.data.likeCount && previousPost.data.likeCount - 1 - : previousPost.data.likeCount && previousPost.data.likeCount + 1; + const newLikeCount = previousPost.isLiked + ? previousPost.likeCount && previousPost.likeCount - 1 + : previousPost.likeCount && previousPost.likeCount + 1; const data = produce(previousPost, (draft: postType) => { - draft.data.isLiked = !previousPost.data.isLiked; - draft.data.likeCount = newLikeCount; + draft.isLiked = !previousPost.isLiked; + draft.likeCount = newLikeCount; }); queryClient.setQueryData(['getPost', queryId], data);