Skip to content

Commit

Permalink
[FE] ✨ Feat : 방명록을 작성하는 커스텀 훅 구현 (codestates-seb#352)
Browse files Browse the repository at this point in the history
  • Loading branch information
nalsae committed Dec 12, 2023
1 parent d0be070 commit 02cd865
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions client/src/hooks/mutation/useAddGuestbookMutation.ts
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 02cd865

Please sign in to comment.