我想做的是导入 React Native 动态路径。
示例:- 从
./screens/${path}
; 导入演示
目前我找到了一种使用懒惰的方法。但它也只有在像这样初始化常量变量时才有效
const demo = 'Path';
let componentPath = `../Screen/${demo}`;
const DynamicComponent = React.lazy(() =>
import(componentPath).then(module => ({default: module.screenm})),
);
我想通过异步存储保存的变量获取路径。不像硬编码变量。当我硬编码变量并且它起作用时。但我无法从异步存储中获取它。我试图找到方法来做到这一点。但我做不到。有什么方法可以做到吗
const demo = 'Path'; // Your dynamic path variable
// Construct the path to your component
let componentPath = `../Screen/${demo}`;
// Dynamically requires the component using the constructed path
const DynamicComponent = require(componentPath).default;
// Render the dynamically imported component
<DynamicComponent />