Skip to content

Instantly share code, notes, and snippets.

@3nvi
Last active February 28, 2019 09:11
Show Gist options
  • Save 3nvi/41ecd49aeed997bca87a1747a0e59845 to your computer and use it in GitHub Desktop.
Save 3nvi/41ecd49aeed997bca87a1747a0e59845 to your computer and use it in GitHub Desktop.
Lazy Load React Components
// ./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