UNPKG

fumadocs-openapi

Version:

Generate MDX docs for your OpenAPI spec

40 lines (38 loc) 781 B
import { useMemo, useRef, useState } from "react"; //#region src/utils/use-query.ts function useQuery(fn) { const [loading, setLoading] = useState(false); const [data, setData] = useState(); const [error, setError] = useState(); const fnRef = useRef(fn); fnRef.current = fn; return useMemo(() => ({ isLoading: loading, data, error, start(...input) { setLoading(true); fnRef.current(...input).then((res) => { setData(res); setError(void 0); }).catch((err) => { setData(void 0); setError(err); }).finally(() => { setLoading(false); }); }, reset() { setData(void 0); setError(void 0); setLoading(false); } }), [ error, data, loading ]); } //#endregion export { useQuery }; //# sourceMappingURL=use-query.js.map