Closed SoloJiang closed 3 years ago
function Home() { const [TargetComponent, error] = useImport(() => import('./targetComponent')); if (!error && TargetComponent) { return <TargetComponent />; } }
rax-use-import 解决的问题:
dynamic import
目前存在的问题:
import
publicPath
rerender
useMemo
本质是解决异步 bundle 在各个加载时机中设置 publicPath 的问题,该问题和 publicPath 的设置机制有关
Example
分析
rax-use-import 解决的问题:
dynamic import
的异步 Promise 写法优化为同步写法,帮助开发者写出了更符合直觉的代码目前存在的问题:
import
的行为是会立即执行的,导致如果设置publicPath
的逻辑在业务 bundle 之后执行,无法控制动态加载代码的publicPath
rerender
时,会重复执行动态获取资源的逻辑(会被useMemo
缓存结果)~