UNPKG

@gravity-ui/data-source

Version:
45 lines 1.64 kB
import _objectSpread from "@babel/runtime/helpers/objectSpread2"; import React from 'react'; import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime"; export var DataInfiniteLoader = function DataInfiniteLoader(_ref) { var status = _ref.status, error = _ref.error, errorActionProp = _ref.errorAction, hasNextPage = _ref.hasNextPage, fetchNextPage = _ref.fetchNextPage, isFetchingNextPage = _ref.isFetchingNextPage, LoadingView = _ref.LoadingView, ErrorView = _ref.ErrorView, MoreView = _ref.MoreView, loadingViewProps = _ref.loadingViewProps, errorViewProps = _ref.errorViewProps, moreViewProps = _ref.moreViewProps, children = _ref.children; var errorAction = React.useMemo(function () { return typeof errorActionProp === 'function' ? { handler: errorActionProp } : errorActionProp; }, [errorActionProp]); var renderContent = function renderContent() { if (status === 'loading') { return /*#__PURE__*/_jsx(LoadingView, _objectSpread({}, loadingViewProps)); } if (status === 'error') { return /*#__PURE__*/_jsx(ErrorView, _objectSpread({ error: error, action: errorAction }, errorViewProps)); } if (status === 'success' && hasNextPage) { return /*#__PURE__*/_jsx(MoreView, _objectSpread({ isLoading: isFetchingNextPage, onClick: fetchNextPage }, moreViewProps)); } return null; }; return /*#__PURE__*/_jsxs(_Fragment, { children: [status === 'success' ? children : null, renderContent()] }); }; // #sourceMappingURL=DataInfiniteLoader.js.map