UNPKG

@navinc/base-react-components

Version:
28 lines 992 B
import PropTypes from 'prop-types'; const WaitForDependencies = ({ children, ErrorContent, LoadingContent, loadingProps, hasDependencyProps }) => { const hasAllDataDependencies = hasDependencyProps.reduce((accumulator, current) => current && accumulator, true); const areAnyLoading = loadingProps.reduce((accumulator, current) => current || accumulator, false); if (hasAllDataDependencies) { return children; } else if (areAnyLoading && LoadingContent) { return LoadingContent; } else if (ErrorContent) { return ErrorContent; } return null; }; WaitForDependencies.defaultProps = { hasDependencyProps: [], loadingProps: [], }; WaitForDependencies.propTypes = { children: PropTypes.node, ErrorContent: PropTypes.node, hasDependencyProps: PropTypes.array, LoadingContent: PropTypes.node, loadingProps: PropTypes.array, }; export default WaitForDependencies; //# sourceMappingURL=wait-for-dependencies.js.map