[英]React Native store screen in object and import that object
I'm starting to learn React Native and faced a problem I'm not able to solve. 我开始学习React Native,并遇到了我无法解决的问题。
In the file Screens.js, I want to store all screens in an object and export said object. 在文件Screens.js中,我想将所有屏幕存储在一个对象中并导出所述对象。
// Screens.js example
import { HelloScreen } from './HelloScreen';
export const screens = {
hello: HelloScreen,
};
Then, I want to import the 'screens' object into App.js an use the 'HelloScreen' there 然后,我想将“屏幕”对象导入App.js,然后在其中使用“ HelloScreen”
import { screens } from './screens/Screens';
export default createStackNavigator({
Home: {
screen: screens.hello
},
});
But'screens' is undefined here. 但是这里没有定义“屏幕”。
What am I doing wrong? 我究竟做错了什么? I'm also getting this error message: The component for route 'Home' must be a React component.
我也收到此错误消息:路由“ Home”的组件必须是React组件。
Thanks in advance for your help. 在此先感谢您的帮助。
I figured it out. 我想到了。 I had to change the way I import 'HelloScreen' in 'Screens.js' from this:
我必须从中更改在“ Screens.js”中导入“ HelloScreen”的方式:
import { HelloScreen } from './HelloScreen';
to this: 对此:
import HelloScreen from './HelloScreen';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.