Android 文本输入值在更改状态后未更新?
这是构造器Android 文本输入值在更改状态后未更新?,android,react-native,state,react-native-textinput,Android,React Native,State,React Native Textinput,这是构造器 onChangeText = (text, id) => { this.setState((previousState) => ({ testEmail: text+'test' } ) ) } 试试这个: constructor(props) { super(props); this.state = { testEma
onChangeText = (text, id) => {
this.setState((previousState) => ({
testEmail:
text+'test'
}
)
)
}
试试这个:
constructor(props) {
super(props);
this.state = {
testEmail: '',
};
}
onChangeText=text=>{
这是我的国家({
testEmail:`${text}测试`
});
}
小吃样本。
shouldComponentUpdate
此方法匿名调用,导致无法更新TextInput
我尝试了您的expo项目,效果很好。但是我复制了完全相同的代码,它在我的项目中不起作用。问题是文本被替换回空字符串。
constructor(props) {
super(props);
this.state = {
testEmail: '',
};
}
<TextInput
label={'Please enter your email'}
onChangeText={this.onChangeText}
style={textInputStyle}
value={this.state.testEmail}
/>
onChangeText = text => {
this.setState({
testEmail: `${text}test`
});
}