[英]React Plugin Architecture with dynamic loading
I want to build a SPA on client site, which supports a plugin concept.我想在客户端站点上构建一个支持插件概念的 SPA。 You should be able to copy a package inside a specific folder and the server should load this component after a restart.您应该能够在特定文件夹中复制包,并且服务器应该在重新启动后加载此组件。 This plugin should work without any information stored inside the base program.这个插件应该可以在没有任何信息存储在基本程序中的情况下工作。
I need to dynamic load a component by name.我需要按名称动态加载组件。 I do not have a map of all possible components.我没有所有可能组件的地图。 How can I load a component by only know their name?如何仅通过知道组件的名称来加载组件?
Thank you for your help.谢谢您的帮助。 :) :)
you can check out React.lazy
.你可以查看React.lazy
。 This helps with dynamic loading components which you want, but with this you need to wrap it to Suspense, because component will load not immediately.这有助于动态加载您想要的组件,但是您需要将它包装到 Suspense,因为组件不会立即加载。
// This component is loaded dynamically const SomeComponent = React.lazy(() => import('./SomeComponent')); <Suspense fallback={<Spinner/>}><SomeComponent/></Suspense>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.