From 02cd8651e7f07739e288310f05527fb80886a186 Mon Sep 17 00:00:00 2001 From: nalsae Date: Tue, 12 Dec 2023 15:51:46 +0900 Subject: [PATCH] =?UTF-8?q?[FE]=20=E2=9C=A8=20Feat=20:=20=EB=B0=A9?= =?UTF-8?q?=EB=AA=85=EB=A1=9D=EC=9D=84=20=EC=9E=91=EC=84=B1=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EC=BB=A4=EC=8A=A4=ED=85=80=20=ED=9B=85=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=20(#352)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hooks/mutation/useAddGuestbookMutation.ts | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 client/src/hooks/mutation/useAddGuestbookMutation.ts diff --git a/client/src/hooks/mutation/useAddGuestbookMutation.ts b/client/src/hooks/mutation/useAddGuestbookMutation.ts new file mode 100644 index 00000000..1a1e7053 --- /dev/null +++ b/client/src/hooks/mutation/useAddGuestbookMutation.ts @@ -0,0 +1,29 @@ +import { useParams } from 'next/navigation'; + +import { useMutation, useQueryClient } from '@tanstack/react-query'; + +import { addGuestbook } from '@/api/garden'; + +import useUserStore from '@/stores/userStore'; + +import { CommentInputValue } from '@/types/common'; + +const useAddGuestbookMutation = () => { + const queryClient = useQueryClient(); + + const { id } = useParams(); + + const { userId } = useUserStore(); + + const { mutate } = useMutation({ + mutationFn: ({ comment }: CommentInputValue) => + addGuestbook(id as string, comment), + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: ['guestbook', userId] }); + }, + }); + + return { mutate }; +}; + +export default useAddGuestbookMutation;