2016-03-07 85 views
3

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'.阵营本地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> 
     ); 
    } 
} 

更新:

弄清楚了。组件应该是小写的。

+1

你忘了在'HackerNews'类定义之前导入'Dashboard'类,可能是什么? – Cherniv

回答

0

您需要在HackerNews组件中导入仪表板类。

+0

你检查过,如果导入返回的东西不是undefined? –

+1

没关系。我想到了。组件应该是小写的。 – qinking126

2

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

我只是强调他的答案在这里。

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

这里组件应该是小写

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

感谢qinking126

+1

这应该是对其他答案的评论,或作为建议编辑提交。 – Mogsdad

相关问题