Skip to content

Instantly share code, notes, and snippets.

@NiallJoeMaher
Created June 9, 2019 13:26
Show Gist options
  • Save NiallJoeMaher/f0cdeb91ec2d22a3b4faaf3731248284 to your computer and use it in GitHub Desktop.
Save NiallJoeMaher/f0cdeb91ec2d22a3b4faaf3731248284 to your computer and use it in GitHub Desktop.
// Before
import OtherComponent from './OtherComponent';
function MyComponent() {
return (
<div>
<OtherComponent />
</div>
);
}
// After
const OtherComponent = React.lazy(() => import('./OtherComponent'));
function MyComponent() {
return (
<div>
<Suspense fallback={<div>Loading...</div>}>
<OtherComponent />
</Suspense>
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment