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>
);
}
}
更新:
弄清楚了。組件應該是小寫的。
你忘了在'HackerNews'類定義之前導入'Dashboard'類,可能是什麼? – Cherniv