Skip to content

Instantly share code, notes, and snippets.

@pomber
Last active April 20, 2020 19:41
Show Gist options
  • Save pomber/0cb1aa7cfb7863b9411390156d97afcb to your computer and use it in GitHub Desktop.
Save pomber/0cb1aa7cfb7863b9411390156d97afcb to your computer and use it in GitHub Desktop.
function lazyWithPreload(factory) {
const Component = React.lazy(factory);
Component.preload = factory;
return Component;
}
const StockChart = lazyWithPreload(() => import("./StockChart"));
// somewhere in your component
...
handleYouMayNeedToRenderStockChartSoonEvent() {
StockChart.preload();
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment