React Native错误:元素类型无效:期望字符串或类/函数但得到:object [英] React Native error: Element type is invalid: expected a string or a class/function but got: object

查看:89
本文介绍了React Native错误:元素类型无效:期望字符串或类/函数但得到:object的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到此错误,我在修复此问题时遇到了很多麻烦。

I am getting this error and I am having a lot of trouble fixing this.

我在这里尝试做的是有3个不同的屏幕并且有一个tabbar导航到每个屏幕。

What I am trying to do here is have 3 different screens and have a tabbar that navigates to each screen.

这是我的索引:

import React, { Component } from 'react';
import { AppRegistry, Navigator, StyleSheet, View, Text } from 'react-native';

import Nav from './app/components/Nav';
import Screen from './app/Screen';

import Tabs from 'react-native-tabs'

import SwitchView from './SwitchView';

class Proj extends Component {

constructor(props){
    super(props);
}

render(){
    var x = "FeedView";
    return(

          <View style={styles.container}>
            <Tabs selected={x} style={{backgroundColor:'white'}}
                  selectedStyle={{color:'red'}} onSelect={el=> {x = el.props.name}}>
                <Text name="FeedView">First</Text>
                <Text name="WikiView" selectedIconStyle={{borderTopWidth:2,borderTopColor:'red'}}>Second</Text>
                <Text name="BoardView">Third</Text>
            </Tabs>

            <SwitchView id={x}/>

          </View>
    );
}
}

const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
})

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

这是我的SwitchView:

here is my SwitchView:

import Feed from './app/pages/Feed/Feed';
import Board from './app/pages/Board';
import Wiki from './app/pages/Wiki';

class SwitchView extends Component {
render(){
    var { id } = this.props;

    switch (id) {
        case "FeedView":
            return <Feed/>
        case "WikiView":
            return <Wiki/>
        case "BoardView":
            return <Board/>
    }
}
}


推荐答案

这可能是由程序中的某些JS模块导出/导入问题引起的,通常是出于以下两种原因之一:


  • 您忘记导出,或导出错误的内容

  • 您导入的内容不存在,或导入的内容不正确

我遇到了类似的错误,但在我的情况下,它不是由 export 引起的,而是由 import ,我错误地使用了 import 语句来导入模块中不存在的内容。

I ran into similar error, but in my case, it is not caused by export but caused by import, and I used the import statement incorrectly to import something that doesn't exist in the module.

在我的情况下, import 被错误地写为:

In my case, the import was incorrectly written as:

从'./MyComponents/MyComponent'导入{MyComponent}

实际上它应该是:

从'./MyComponents/MyComponent'导入MyComponent

这让我疯了,花了我一整天的时间才想出来,我希望这会为一些人节省几个小时。

And it drove me crazy and took me a whole day to figure it out and I hope this will save several hours for some people.

这篇关于React Native错误:元素类型无效:期望字符串或类/函数但得到:object的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆