<TextInput
placeholder="Full Name"
onChangeText={userName => this.setState({ userName })}
onChangeText={text => this.validate(text, "username")}
underlineColorAndroid="transparent"
style={[
styles.TextInputStyleClass,
!this.state.nameValidate ? styles.error : null
]}
blurOnSubmit={false}
autoFocus={true}
autoCorrect={true}
autoCapitalize="none"
maxLength={25}
/>
在上面的代码中,我使用了两个Onchagnetext事件,但仅在调用验证的事件工作中,另一个不工作意味着没有取值。为什么要修理它。我怎样才能使用两个Onchangetext事件?
你不需要两个onChangeText
方法。
如果要一起验证和使用setState,那么你可以这样做
...
onChangeText={userName => this.setState({ userName },
() => this.validate(username, 'username)})}
setState
中的回调确保您在setState
完成更新state
后调用该方法