UNPKG

@navinc/base-react-components

Version:
32 lines (25 loc) 890 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