Atul Tiwari
Atul Tiwari

Reputation: 604

how to use two onChangeText in react native inside textinput

<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?

Upvotes: 2

Views: 2240

Answers (1)

Pritish Vaidya
Pritish Vaidya

Reputation: 22209

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

Upvotes: 2

Related Questions