I have seen the webpack documentation for dynamic imports (refer below image), but this doesn't seem to work in react as we return components directly in React rather than adding elements to DOM (after then() of the promise).
In React lazy loading documentation, they have shown how to lazy load only other React components but not how to dynamic import NPM libraries.
So if someone could explain how to dynamic import npm modules, that would be great.
the NPM package imports follow it is component, so if we dynamically imported the component that means we dynamically imported the Package, since the
import
does not get called until it is component gets calledFor further information about code splitting read this article it goes throw all the techniques you can use to achieve code splitting
https://blog.logrocket.com/react-dynamic-imports-route-centric-code-splitting-guide/