import { useState, useEffect } from "react"; interface HookResult { isPending: boolean error: Error | null data: T | null } type ApiMethod = () => Promise export function useApiCall(apiMethod: ApiMethod): HookResult { const [data, setData] = useState(null) const [error, setError] = useState(null) const [isPending, setIsPending] = useState(true) useEffect(() => { apiMethod() .then((data: T) => setData(data)) .catch((error: Error) => setError(error)) .finally(() => setIsPending(false)) }, [apiMethod]) return { isPending, error, data } }