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'] }), }); };