React.lazy makes code splitting a one-liner, as long as the component you load is a default export. Most codebases I work in use named exports, so I needed a way to lazy load them without rewriting every module.
👉 Continue reading on my blog: 🦥 React.lazy without a default export
Top comments (5)
Thank you!
Does this have an affect on tree-shaking?
Yes. Dynamic import cannot be analyzed at build time.
You will have to follow React Docs and reexport only wanted component to have dynamic import with tree shaking
reactjs.org/docs/code-splitting.ht...
Excellent. Thanks for the link.
Thank you!