2
<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}
/> 

in the above code, I use two Onchagnetext events but only on event work that calls validation another is not working means not take value. why how to fix it. how can I use two Onchangetext events?

1
  • Do you want both of them work at the same time? Commented Sep 19, 2018 at 11:38

1 Answer 1

2

You don't need two onChangeText method.

If you want to validate and use setState together then you can do

   ...
   onChangeText={userName => this.setState({ userName },
    () => this.validate(username, 'username)})} 

The callback in setState ensures that you are calling the method once the setState has finished updating the state

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.