Created
December 10, 2020 12:14
-
-
Save PaquitoSoft/52223913ab51403a1912cbdee0e35a19 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Suspense } from 'react'; | |
import PropTypes from 'prop-types'; | |
import { useResponsive } from './responsive-provider'; | |
const SuspenseFallback = () => (null); | |
function ResponsiveComponent({ | |
xs, | |
sm, | |
lg, | |
md, | |
xl, | |
xxl, | |
loadingComponent, | |
children, | |
...props | |
}) { | |
const { selectResponsiveComponent } = useResponsive(); | |
const Fallback = loadingComponent || SuspenseFallback; | |
const Component = selectResponsiveComponent({ xs, sm, md, lg, xl, xxl }); | |
return ( | |
<Suspense fallback={<Fallback />}> | |
<Component {...props}>{children}</Component> | |
</Suspense> | |
); | |
} | |
ResponsiveComponent.propTypes = { | |
xs: PropTypes.func, | |
sm: PropTypes.func, | |
md: PropTypes.func, | |
lg: PropTypes.func, | |
xl: PropTypes.func, | |
xxl: PropTypes.func, | |
loadingComponent: PropTypes.elementType, | |
children: PropTypes.node | |
}; | |
export default ResponsiveComponent; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment