我很難搞清楚爲什麼我得到的輸入使用此代碼返回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>
);
}
}
在
LoginForm.js
進口<Input/
進口在示例代碼中顯示您在'Index.js'了''成分,但'import'在'LoginForm.js'從'。/'中導入''。這是應用程序如何導入它們嗎? –感謝讓燈泡熄滅。它以'undefined'返回,因爲它從未在保存對App的所有輸出的'index.js'文件中輸出。謝謝!! – Brandon