Source

apis/InvestmentPortfolio.js

import { useQuery } from "@tanstack/react-query";
import Axios from "../utils/ApiConfiguration";

/**
 * Custom hook to fetch investment portfolio data.
 *
 * This hook fetches investment portfolio data from the server using the `useQuery` hook from "@tanstack/react-query."
 *
 * @returns {Object} The query result object containing data, loading status, and possible errors.
 * @throws {Error} If there's an issue with fetching investment portfolio data.
 *
 * @example
 * // Usage of useGetInvestmentPortfolio hook
 * const { data, isLoading, error } = useGetInvestmentPortfolio();
 * if (isLoading) {
 *   return <p>Loading...</p>;
 * }
 * if (error) {
 *   return <p>Error: {error.message}</p>;
 * }
 * // Render investment portfolio data
 * return (
 *   <div>
 *     <h1>Investment Portfolio</h1>
 *      Render data here
 *   </div>
 * );
 */
export const useGetInvestmentPortfolio = () =>
  useQuery({
    queryKey: ["investment_portfolio"],
    queryFn: () => Axios.get("investmentportfolio/"),
    refetchOnWindowFocus: false,
  });