2016-03-07 86 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

相關問題