import { useEffect, useState } from 'react'; import { ApiMaps } from '../constants/apis'; import { request, RequestOptions } from '../utils'; export default function useRequest( url: T, options?: RequestOptions, ) { const [loading, setLoading] = useState(false); const [data, setData] = useState(null); const [error, setError] = useState(null); useEffect(() => { setLoading(true); request(url, options) .then((res) => { setLoading(false); setData(res); }) .catch((error) => { setLoading(false); setError(error); }); // eslint-disable-next-line react-hooks/exhaustive-deps }, [url, JSON.stringify(options)]); return { data, error, loading, }; }