All files / src/mutations useFavoriteMovieMutation.ts

14.28% Statements 1/7
100% Branches 0/0
0% Functions 0/3
14.28% Lines 1/7

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 23 24          5x                                    
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { toast } from "react-toastify";
import { setFavoriteMovie } from "@/api";
import { IFavoriteMoviePayload } from "@/interfaces";
 
const useFavoriteMovieMutation = () => {
  const queryClient = useQueryClient();
 
  const { mutate: setFavoriteMutation, ...mutationState } = useMutation({
    mutationFn: (payload: IFavoriteMoviePayload) => setFavoriteMovie(payload),
    onSuccess: (msg) => {
      toast(msg.status_message);
      queryClient.invalidateQueries({ queryKey: ["movieDetails"] });
    },
  });
 
  return {
    setFavoriteMutation,
    ...mutationState,
  };
};
 
export default useFavoriteMovieMutation;