Javascript 元素类型无效:应为字符串/类/函数Get:对象
我正在从事React原生项目,在尝试实现React导航时遇到问题。 我遵循了一个教程,在尝试运行该项目时,出现了一个错误,显示:Javascript 元素类型无效:应为字符串/类/函数Get:对象,javascript,react-native,Javascript,React Native,我正在从事React原生项目,在尝试实现React导航时遇到问题。 我遵循了一个教程,在尝试运行该项目时,出现了一个错误,显示: Element 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
Element 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.
我搜索了网站,包括这个网站,但找不到任何解决方案。
这是我的代码:
index.js:
import React, { Component } from 'react';
import { Stack } from './config/Router';
class Application extends Component{
render(){
<View>
return <Stack />;
</View>
}
}
export default Application;
这是index.ios.js:
import { AppRegistry } from 'react-native';
import Application from './index'
AppRegistry.registerComponent('Application', () => Application);
我如何修复错误?提前谢谢 看起来像
类应用程序扩展组件{
render(){
返回;
}
}
应该是
类应用程序扩展组件{
render(){
返回(
);
}
}
您还需要在index.js中导入视图组件
您可能忘记了从定义组件的文件中导出组件。
这几乎总是导致出现无效元素错误的原因,因此请始终仔细检查导入内容。@JohnDoah您可能需要导入index.js中的视图组件
import { AppRegistry } from 'react-native';
import Application from './index'
AppRegistry.registerComponent('Application', () => Application);