@resourge/react-fetch
Version:
[](LICENSE)
30 lines (26 loc) • 836 B
JavaScript
/**
* react-fetch v1.43.1
*
* Copyright (c) resourge.
*
* This source code is licensed under the MIT license found in the
* LICENSE.md file in the root directory of this source tree.
*
* @license MIT
*/
import { useSyncExternalStore, useCallback } from 'react';
import { LoadingService } from '@resourge/http-service';
import { globalLoading } from './globalLoader/constants';
import { jsx, Fragment } from 'react/jsx-runtime';
const Loader = ({
loaderId,
children,
loadingElement = globalLoading
}) => {
const loading = useSyncExternalStore(useCallback(notify => LoadingService.addListener(loaderId, notify), [loaderId]), () => LoadingService.getLoading(loaderId));
return jsx(Fragment, {
children: loading ? loadingElement : children
});
};
export { Loader as default };
//# sourceMappingURL=Loader.js.map