import { useMutation, useQuery } from "@tanstack/react-query";
import Axios from "../utils/ApiConfiguration";
/**
* Custom hook to fetch an invoice by its ID.
*
* This hook fetches an invoice by its ID from the server using the `useQuery` hook from "@tanstack/react-query."
*
* @param {string} id - The ID of the invoice to fetch.
* @returns {Object} The query result object containing the invoice data, loading status, and possible errors.
* @throws {Error} If there's an issue with fetching the invoice data.
*
* @example
* // Usage of useGetInvoice hook
* const { data, isLoading, error } = useGetInvoice("invoice_id_here");
* if (isLoading) {
* return <p>Loading...</p>;
* }
* if (error) {
* return <p>Error: {error.message}</p>;
* }
* // Render invoice data
* return (
* <div>
* <h1>Invoice Details</h1>
* Render data here
* </div>
* );
*/
export const useGetInvoice = (id) =>
useQuery({
queryKey: ["invoices", id],
queryFn: () => Axios.get(`invoice/${id}/`),
refetchOnWindowFocus: false,
});
Source