import type { PortfolioData } from "@/data/portfolio"; import { useUtils } from "./useUtils"; export const useAPI = (baseURL = window.API_URL, key = window.API_KEY) => { const { url } = useUtils(); const normalizedURL = url.normalizePath(baseURL.trim()); const generateURL = (path: string) => { return normalizedURL + path; }; const getPortfolioData = async () => fetch(generateURL("/keyvalue?key=portfolio")) .then((resp) => resp.json()) .then((data: { key: string; value: string }[]) => data.length > 0 && data[0] ? (JSON.parse(data[0].value) as PortfolioData) : undefined, ) .catch(() => undefined); return { getPortfolioData, }; };