gpt4 book ai didi

javascript - 元素类型无效 : expected a string/class/function got: object

转载 作者:太空宇宙 更新时间:2023-11-04 15:47:36 27 4
gpt4 key购买 nike

我正在开发 React-Native 项目,在尝试实现 React-navigation 时遇到了问题。我按照教程进行操作,当尝试运行该项目时,出现错误:

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.

我搜索了网络,包括这个网站,但找不到任何解决方案。这是我的代码:索引.js:

import React, { Component } from 'react';
import { Stack } from './config/Router';

class Application extends Component{
render(){
<View>
return <Stack />;
</View>
}
}

export default Application;

这是路由器:

import React from 'react';
import { StackNavigator } from 'react-navigation';

import Login from '../components/Login';
import Home from '../components/Home';

export const Stack = StackNavigator({
Login:{
screen: Login
},
Home:{
screen: Home,
navigationOptions: {
title: 'Home'
}
}
});

这是index.ios.js:

import { AppRegistry } from 'react-native';
import Application from './index'

AppRegistry.registerComponent('Application', () => Application);

如何修复该错误?提前致谢!

最佳答案

看起来像

class Application extends Component{
render(){
<View>
return <Stack />;
</View>
}
}

应该是

class Application extends Component{
render(){
return(
<View>
<Stack />
</View>
);
}
}

您还需要在index.js中导入View组件

您可能忘记从定义它的文件中导出组件。

这几乎总是您收到无效元素错误的原因,因此请务必仔细检查您的导入。

关于javascript - 元素类型无效 : expected a string/class/function got: object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43428562/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com