2017-09-28 39 views
0

儘管代碼看起來很準確,但React本機拋出了這個奇怪的異常。我正在使用react-native 0.48。Android模擬器錯誤 - 期望獲得[object,object]的組件類

圍護index.js和login.js源代碼

Login.js

import React, { Component } from "react"; 
import { 
    AppRegistry, 
    Text, 
    View, 
    TouchableOpacity, 
    Label, 
    TextInput 
} from "react-native"; 
import { StackNavigator } from "react-navigation"; 
class LoginPage extends Component { 
    constructor(props) { 
    super(props); 
    } 

    render(){ 
    // const { navigate } = this.props.navigation; 
    return(
     <View> 
     <Label Text="Login" /> 
     <TextInput placeholder="UserName" /> 
     <TextInput placeholder="Password" /> 
     <TouchableOpacity Text="Login" /> 
     </View> 
    ); 
    } 
} 

export default LoginPage; 

Index.js

//Root Component 

import React, { Component } from "react"; 
import { AppRegistry, View, Text } from "react-native"; 
import Root from "./config/router.js"; 
import LoginPage from './components/user/Login'; 
class App extends React.Component { 
    render() { 
    return (

     <View> 
     <LoginPage /> 
     <Text>this is index component </Text> 
     </View> 
    ); 
    } 
} 

export default App; 

連我都看計算器問題有關這個問題 StackOverflow .. Stilll我不能夠f找出問題。

router.js

//Screen router 
import React, { Component } from "react"; 
import { StackNavigator } from "react-navigation"; 
import LoginPage from "../components/user/Login"; 
import Register from "../components/user/Register"; 
//import App from "../index"; 

export const Root = StackNavigator({ 
    login: { screen: LoginPage }, 
    Register:{screen:Register} 
}); 

回答

0

你不能使用首字母作爲一個小後者爲您的組件如果要導入或使用it.first組件的後者必須是大寫,否則你會得到這個錯誤

<label Text="Login" /> //invalid 
<Label Text="Login" /> //Valid 
+0

現在它的渲染'期望一個字符串或類/函數,但沒有定義。 '使用router.js文件更新我的問題tooo –

+0

由於Label不是react-native的一部分,如果您想使用Label然後使用native-base,則使用native-base fire命令「npm install native-base - -save「,然後從中導入標籤 –

+0

從所有文件中刪除標籤。仍然顯示這個錯誤'期望一個字符串或類/函數,但沒有定義。您可能會忘記將組件從其定義的文件中導出。檢查應用程序' –

相關問題