import { jsx } from "react/jsx-runtime";
import { createContext, useContext } from "react";
import { useRequest } from "../api-client/index.mjs";
const AsyncDataContext = /*#__PURE__*/ createContext(null);
AsyncDataContext.displayName = 'AsyncDataContext';
const AsyncDataProvider = (props)=>{
    const { value, request, children, ...others } = props;
    const result = useRequest(request, {
        ...others
    });
    if (value) return /*#__PURE__*/ jsx(AsyncDataContext.Provider, {
        value: value,
        children: children
    });
    return /*#__PURE__*/ jsx(AsyncDataContext.Provider, {
        value: result,
        children: children
    });
};
const useAsyncData = ()=>useContext(AsyncDataContext);
export { AsyncDataContext, AsyncDataProvider, useAsyncData };
