No, currently
function supports default exports only. If you would like to import modules which are named exports, you can create an intermediate module that reexports it as the default. It also ensures that tree shaking keeps working and don’t pull unused components. Let's take a component file which exports multiple named components,React.lazy
// MoreComponents.jsexport const SomeComponent = /* ... */;export const UnusedComponent = /* ... */;
and reexport
components in an intermediate fileMoreComponents.js
IntermediateComponent.js
// IntermediateComponent.jsexport { SomeComponent as default } from "./MoreComponents.js";
Now you can import the module using lazy function as below,
import React, { lazy } from "react";const SomeComponent = lazy(() => import("./IntermediateComponent.js"));