Reactjs 从url动态加载react本机组件
是否可以在react-native中动态加载和缓存远程react-native组件Reactjs 从url动态加载react本机组件,reactjs,react-native,Reactjs,React Native,是否可以在react-native中动态加载和缓存远程react-native组件 我们希望能够构建和部署部分UI及其各自的后端微服务,以便配置客户端集中使用的组件/后端组合。在xcode中打开ios项目,并查看AppDelegate.m NSURL *jsCodeLocation; #ifdef DEBUG /** * Loading JavaScript code - uncomment the one you want. * * OPTION 1
我们希望能够构建和部署部分UI及其各自的后端微服务,以便配置客户端集中使用的组件/后端组合。在xcode中打开ios项目,并查看AppDelegate.m
NSURL *jsCodeLocation;
#ifdef DEBUG
/**
* Loading JavaScript code - uncomment the one you want.
*
* OPTION 1
* Load from development server. Start the server from the repository root:
*
* $ npm start
*
* To run on device, change `localhost` to the IP address of your computer
* (you can get this by typing `ifconfig` into the terminal and selecting the
* `inet` value under `en0:`) and make sure your computer and iOS device are
* on the same Wi-Fi network.
*/
jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/compiled/src/index.ios.bundle?platform=ios&dev=true"];
#else
/**
* OPTION 2
* Load from pre-bundled file on disk. The static bundle is automatically
* generated by the "Bundle React Native code and images" build step when
* running the project on an actual device or running the project on the
* simulator in the "Release" build configuration.
*/
jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
如您所见,它已经支持远程和本地加载捆绑包。出于性能原因,生产中绝对不建议远程加载它
您可以查看和之类的工具。它们帮助您动态推出更新
尽管没有一个替代方案可以解决这里提出的问题:如何动态加载单个组件。由于您可以在JS中远程加载和评估资源,并且只需要返回使用有效react本机组件的有效JSX,这绝对不是不可能的 我认为这样我们可以从服务器加载整个应用程序;你有没有找到一种方法,只为几个组件做这件事?