Last active
February 28, 2019 09:11
-
-
Save 3nvi/41ecd49aeed997bca87a1747a0e59845 to your computer and use it in GitHub Desktop.
Lazy Load React Components
This file contains 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
// ./Tooltip.jsx | |
const MUITooltip = React.lazy(() => import('@material-ui/core/Tooltip')); | |
function Tooltip({ children, title }) { | |
return ( | |
<React.Suspense fallback={children}> | |
<MUITooltip title={title}> | |
{children} | |
</MUITooltip> | |
</React.Suspense> | |
); | |
} | |
// ./Component.jsx | |
function Component(props) { | |
return ( | |
<Tooltip title={props.title}> | |
<AnotherComponent /> | |
</Tooltip> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment