[英]Unable to type inside text-input in React Native
I've got the following class:我有以下 class:
export default class DonationFormScreen extends React.Component {
constructor(props) {
super(props);
this.state = {
title: this.props.title,
};
}
state = {
units: '0',
comment: '-'
}
render() {
let institution=this.props.route.params.institution;
let title = this.props.route.params.title;
return (
<View>
<View style={styles.container}>
<Text style={styles.label}>¿Cuántas unidades?</Text>
<TextInput
style={styles.input}
placeholder="Unidades..."
onChangeText={(text) => this.setState({units:text})}
/>
<Text style={styles.label}>¿Algún otro comentario?</Text>
<TextInput
style={styles.input}
placeholder="Comentar..."
onChangeText={(text) => this.setState({comment:text})}
/>
<View style={styles.button}>
<Button color="white" title="Donar"/>
</View>
</View>
</View>
);
}
}
Turns out I'm unable to type inside my textinputs.结果我无法在我的文本输入中输入。 Whenever I click on them I can get the placeholder to disappear and it seems to let me type but nothing gets written on screen.
每当我点击它们时,我都会让占位符消失,它似乎让我可以打字,但屏幕上什么也没有写。
You didn't give initial value to your Text Input你没有给你的文本输入初始值
<TextInput
value={this.state.units}
style={styles.input}
placeholder="Unidades..."
onChangeText={(text) => this.setState({units:text})}
/>
and the same goes for comment TextInput评论 TextInput 也是如此
<TextInput
value={this.state.comment}
style={styles.input}
placeholder="Comentar..."
onChangeText={(text) => this.setState({comment:text})}
/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.