react-native - react 原生 NavigatorIOS 错误 : Element type is invalid expected a string or a class/function

标签 react-native

Element type is invalid: expected a string(for built-in components) or a class/function (for composite components) but got: undefined. check the render method of 'NavigatorIOS'.

这是我的代码

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 */
'use strict';

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

var Dashboard = require('./App/Views/Dashboard/index.ios.js');

class HackerNews extends React.Component {
    render() {
        return (

            <NavigatorIOS style={styles.container}
                tintColor='#FF6600'
                initialRoute={{
                    title: 'Hacker News',
                    Component: Dashboard,
                }}/>
        );
    }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#F6F6FF',
  },

});

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

仪表板代码:

'use strict';

import React, {
    StyleSheet,
    Text,
    View,
    TouchableHighlight,
} from 'react-native';

//var api = require("../../Network/api.js");
//var Post = require("../Post/index.ios.js");

export default class Dashboard extends React.Component {
    constructor(props){
        super(props);
        this.state = {
            topStoryIDs: null,
            lastIndex: 0
        };
    }

    render(){
        return(
            <View>
                <Text>Dashboard Testing</Text>
            </View>
        );
    }
}

更新:

想通了。组件应该是小写的。

最佳答案

@qinking126 已经能够解决这个问题,他评论了他的答案。

我只是在此处突出显示他的答案。

<NavigatorIOS style={styles.container}
            tintColor='#FF6600'
            initialRoute={{
                title: 'Hacker News',
                Component: Dashboard,
            }}/>

这里 Component 应该小写

像这样:- 组件:仪表板,

感谢qinking126

关于react-native - react 原生 NavigatorIOS 错误 : Element type is invalid expected a string or a class/function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35841317/

相关文章:

android - 任务 ':app:mergeDebugResources' 执行失败。 react native,目前正在尝试在Android上运行

javascript - 如何在 react 导航中连接 react 组件?

testing - 让 Mocha 与 React Native 一起工作 - 错误 w/requiring & addons

javascript - react native : ListView not displaying all rows

react-native - 如何将带有成员变量的 react 组件重构为 es6 类

javascript - 使用 axios 使用签名链接将图像放入 Digital Ocean 空间时出现 "SignatureDoesNotMatch"

react-native - Realm React-Native 中的嵌套对象

android - React Native 中 SimpleSettableFuture.java 反复崩溃

react-native - 尝试添加 mailto - react native

react-native - 无法解析依赖树 - React Native Expo