UNPKG

mod-arch-shared

Version:

Shared library for modular architecture micro-frontend projects

22 lines 800 B
import * as React from 'react'; export const useAPIState = (hostPath, createAPI) => { const [internalAPIToggleState, setInternalAPIToggleState] = React.useState(false); const refreshAPIState = React.useCallback(() => { setInternalAPIToggleState((v) => !v); }, []); const apiState = React.useMemo(() => { let path = hostPath; if (!path) { // TODO: we need to figure out maybe a stopgap or something path = ''; } const api = createAPI(path); return { apiAvailable: !!path, api, }; // eslint-disable-next-line react-hooks/exhaustive-deps }, [createAPI, hostPath, internalAPIToggleState]); return [apiState, refreshAPIState]; }; //# sourceMappingURL=useAPIState.js.map