All files / src/hooks/use-follower/use-follower-add index.ts

81.81% Statements 18/22
100% Branches 1/1
25% Functions 1/4
81.81% Lines 18/22

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 231x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x     1x     1x 1x 1x  
import { useMutation, useQueryClient } from '@tanstack/react-query';
 
import { API } from '@/api';
import { AddFollowParams } from '@/types/service/follow';
 
export const useAddFollowers = (
  { userId }: { userId: number },
  options?: { enabled?: boolean },
) => {
  const queryClient = useQueryClient();
  const query = useMutation({
    mutationFn: (params: AddFollowParams) => API.followerService.addFollower(params),
    ...options,
    onSuccess: () => {
      queryClient.invalidateQueries({ queryKey: ['followers', userId] });
    },
    onError: (error) => {
      throw error;
    },
  });
  return query;
};