问题描述
`这是我的尝试,只需单击一个按钮即可动态加载组件,并显示在页面上。 https://codesandbox.io/s/sweet-haze-knste?file=/src/App.tsx
单击按钮后,我使用下面的代码行动态导入组件。
const importedComponent = React.lazy(() => import("./DynamicallyImportedComponent"));
然后使用
设置状态this.setState({
importModule: importedComponent
// importModule: CommonEditorCallout
});
但是,这不能正确显示。
当我使用下面的常规导入时,它呈现得很好
import DynamicallyImportedComponent from "./DynamicallyImportedComponent";
这可能是由于在常规导入中我指定了要导入的组件的名称,还是与动态导入本身有关?