Skip to content

Instantly share code, notes, and snippets.

@undrafted
Created March 6, 2020 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save undrafted/1ede68863eedd537db576c829717f148 to your computer and use it in GitHub Desktop.
Save undrafted/1ede68863eedd537db576c829717f148 to your computer and use it in GitHub Desktop.
const preloadLazy = (dynamicImport) => {
let promise;
function load() {
if(!promise) {
promise = dynamicImport();
}
return promise;
}
const component = React.lazy(load);
component.preload = load;
return component;
}
const MyComponent = preloadLazy(() => import('../MyComponent'));
// MyComponent.preload()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment