From d26ece656fbce83cc7f665361c629442f9b0145d Mon Sep 17 00:00:00 2001 From: Leejin-Yang Date: Wed, 20 Sep 2023 01:06:20 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=A2=8B=EC=95=84=EC=9A=94=20=EC=9A=94?= =?UTF-8?q?=EC=B2=AD=20=EC=84=B1=EA=B3=B5=EC=8B=9C=20=EB=A6=AC=EB=B7=B0?= =?UTF-8?q?=EC=99=80=20=EA=BF=80=EC=A1=B0=ED=95=A9=20=EC=83=81=EC=84=B8=20?= =?UTF-8?q?=EC=BF=BC=EB=A6=AC=20invalidate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/hooks/queries/recipe/useRecipeFavoriteMutation.ts | 5 ++++- .../src/hooks/queries/review/useReviewFavoriteMutation.ts | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/frontend/src/hooks/queries/recipe/useRecipeFavoriteMutation.ts b/frontend/src/hooks/queries/recipe/useRecipeFavoriteMutation.ts index 7d5e8ad7f..c97b392af 100644 --- a/frontend/src/hooks/queries/recipe/useRecipeFavoriteMutation.ts +++ b/frontend/src/hooks/queries/recipe/useRecipeFavoriteMutation.ts @@ -1,4 +1,4 @@ -import { useMutation } from '@tanstack/react-query'; +import { useMutation, useQueryClient } from '@tanstack/react-query'; import { recipeApi } from '@/apis'; import type { RecipeFavoriteRequestBody } from '@/types/recipe'; @@ -10,8 +10,11 @@ const patchRecipeFavorite = (recipeId: number, body: RecipeFavoriteRequestBody) }; const useRecipeFavoriteMutation = (recipeId: number) => { + const queryClient = useQueryClient(); + return useMutation({ mutationFn: (body: RecipeFavoriteRequestBody) => patchRecipeFavorite(recipeId, body), + onSuccess: () => queryClient.invalidateQueries({ queryKey: ['recipeDetail', recipeId] }), }); }; diff --git a/frontend/src/hooks/queries/review/useReviewFavoriteMutation.ts b/frontend/src/hooks/queries/review/useReviewFavoriteMutation.ts index 1c72b593b..0d35ab610 100644 --- a/frontend/src/hooks/queries/review/useReviewFavoriteMutation.ts +++ b/frontend/src/hooks/queries/review/useReviewFavoriteMutation.ts @@ -1,4 +1,4 @@ -import { useMutation } from '@tanstack/react-query'; +import { useMutation, useQueryClient } from '@tanstack/react-query'; import { productApi } from '@/apis'; import type { ReviewFavoriteRequestBody } from '@/types/review'; @@ -10,8 +10,11 @@ const patchReviewFavorite = (productId: number, reviewId: number, body: ReviewFa }; const useReviewFavoriteMutation = (productId: number, reviewId: number) => { + const queryClient = useQueryClient(); + return useMutation({ mutationFn: (body: ReviewFavoriteRequestBody) => patchReviewFavorite(productId, reviewId, body), + onSuccess: () => queryClient.invalidateQueries({ queryKey: ['product', productId, 'review'] }), }); };