Skip to content

Commit

Permalink
fix: useMutationPostLike type에서 data 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
j-nary committed Oct 9, 2024
1 parent d185a08 commit 2487b4f
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/api/post/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down

0 comments on commit 2487b4f

Please sign in to comment.