打开应用程序时显示错误。
Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in.
这是我创建的基本代码。请参见复制步骤:
使用命令
create-react-native-app AwesomeProject
创建的本机项目已安装
npm install --save react-navigation
将以下代码从react导航文档粘贴到App.js
import React from 'react';
import {
AppRegistry,
Text,
} from 'react-native';
import { StackNavigator } from 'react-navigation';
class HomeScreen extends React.Component {
static navigationOptions = {
title: 'Welcome',
};
render() {
return <Text>Hello, Navigation!</Text>;
}
}
const SimpleApp = StackNavigator({
Home: { screen: HomeScreen },
});
AppRegistry.registerComponent('SimpleApp', () => SimpleApp);
使用
npm start
运行应用程序并在android expo app中打开请注意,其他文件均未编辑。
最佳答案
Expo和标准React Native项目模板的声明应用程序根组件的方式略有不同。
在标准React Native项目中,您在index.android.js
中使用AppRegistry:
AppRegistry.registerComponent('SimpleApp', () => SimpleApp);
在Expo中,框架为您注册了组件,您要做的就是从
Main.js
导出组件:export default SimpleApp;
这是修改并粘贴到Expo Snack的代码的示例:https://snack.expo.io/S1CZnFadZ
关于javascript - React Native导航包错误React.createElement:类型无效-预期为字符串,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45880180/