2017-07-30 5 views
-1

このコードで入力が返された理由はわかりません。undefinedButton, Card, CardSectionコンポーネントは同じ方法でエクスポート/インポートされます。要素タイプが無効です:文字列/オブジェクトが取得されました:未定義

<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を働いていない - それはindex.jsファイル番目に輸出されることはなかったので、それがundefinedとして返されたワーキング

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/でインポートを示し、 'LoginForm.js'は'。/ 'から' 'をインポートします。それは、アプリがそれらをどのようにインポートするのでしょうか? –

+0

電球をオフにしていただきありがとうございます。 Appへのすべてのエクスポートを保持する 'index.js'ファイルにエクスポートされなかったため、' undefined'として返されました。ありがとう!! – Brandon

答えて

0

atはAppへのすべての輸出を保有しています。サンプルコードで

はあなたがIndex.js` `で` ` コンポーネントが、` import`中を示し Index.js<Input/>コンポーネントが、サンプルコードで ./.

+0

それはまさにそれです。私は上記の 'index.js'ファイルからエクスポートしませんでした! – Brandon

関連する問題