React Lazy imports using named imports
How could I import named imports using lazy syntax?
Before we could use
import { MainComponent, Component1, Component2 } from './components';
How to achieve something like this (although this does not work)?:
const { MainComponent, Component1, Component2 } = React.lazy(() => import('./components'));
Solution 1:
Currently named imports are not supported for React.lazy
:
This RFC has a limited surface. It's targeted at the main use case we want to start handling (default imports). There is a door open for supporting named imports in future RFCs, but it is out of scope of this one. This one is intentionally very limited. We expect to understand this problem space more within the next several months and then we can revisit that discussion with a better understanding. reactjs/rfcs#64 (comment)