2017-07-30 39 views
-1

我很難搞清楚爲什麼我得到的輸入使用此代碼返回undefined。正在以相同的方式導出/導入Button, Card, CardSection組件。元素類型無效:期望獲得的字符串/對象:undefined

如果我註釋掉<Input/>標記,LoginForm中的其餘組件將呈現良好。

任何幫助將不勝感激!

Input.js - 不工作

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

const Input = ({ label, value, onChangeText }) => { 
    return (
     <View> 
      <Text>{label}</Text> 
      <TextInput 
       value={value} 
       onChangeText={onChangeText} 
       style={{ height:20, width:100 }} 
      /> 
     </View> 
    ); 
}; 

export { Input }; 

Button.js - 工作

const Button = ({ whenPressed, children }) => { 

    const { buttonStyle, textStyle } = styles; 

    return (
     <TouchableOpacity onPress={whenPressed} style={buttonStyle}> 
      <Text style={textStyle}> 
       {children} 
      </Text> 
     </TouchableOpacity> 
     ); 
}; 

export { Button }; 

LoginForm.js

import React, { Component } from 'react'; 
import { View } from 'react-native'; 
import { Button, Card, CardSection, Input } from './'; 

class LoginForm extends Component { 

    state = { text: '' }; 

    render() { 
     return(
      <Card> 
       <CardSection> 
        <Input 
         value={this.state.text} 
         onChangeText={text=> this.setState({ text })} 
        /> 
       </CardSection> 
       <CardSection/> 
       <CardSection> 
        <Button style={styles.buttonStyle}>LOGIN</Button> 
       </CardSection> 
      </Card> 
     ); 
    } 
} 
+1

LoginForm.js進口<Input/進口在示例代碼中顯示您在'Index.js'了''成分,但'import'在'LoginForm.js'從'。/'中導入''。這是應用程序如何導入它們嗎? –

+0

感謝讓燈泡熄滅。它以'undefined'返回,因爲它從未在保存對App的所有輸出的'index.js'文件中輸出。謝謝!! – Brandon

回答

0

,因爲它從來沒有在index.js文件導出個它返回undefined在持有所有出口到應用程序。

在示例代碼中顯示您在Index.js<Input/>組件,但是從./.

+0

就是這樣。正如我上面提到的,我沒有從'index.js'文件中導出它! – Brandon

相關問題