@gravity-ui/data-source
Version:
A wrapper around data fetching
31 lines • 1.06 kB
JavaScript
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
import React from 'react';
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
export var DataLoader = function DataLoader(_ref) {
var status = _ref.status,
error = _ref.error,
errorActionProp = _ref.errorAction,
LoadingView = _ref.LoadingView,
ErrorView = _ref.ErrorView,
loadingViewProps = _ref.loadingViewProps,
errorViewProps = _ref.errorViewProps,
children = _ref.children;
var errorAction = React.useMemo(function () {
return typeof errorActionProp === 'function' ? {
handler: errorActionProp
} : errorActionProp;
}, [errorActionProp]);
if (status === 'loading') {
return /*#__PURE__*/_jsx(LoadingView, _objectSpread({}, loadingViewProps));
}
if (status === 'error') {
return /*#__PURE__*/_jsx(ErrorView, _objectSpread({
error: error,
action: errorAction
}, errorViewProps));
}
return /*#__PURE__*/_jsx(_Fragment, {
children: children
});
};
// #sourceMappingURL=DataLoader.js.map