React native onKeyPress is not working?

Viewed 15152

I have just placed TextInput KeyboardType ={"numeric"} just trying to find weather user enter '-' if means I have to event.preventDefault() in OnChange first.Later tried in onKeyPress but onKeyPress is not trigerring , I was just tried to do that but it allowing me to type shows warning Synthetic Event Performance issue.

guys help me .

4 Answers

Here is the solution to this issue of synthetic event:

Input element:

<Input onKeyPress = {this.keyPress} />

keyPress function

keyPress = (event) => {

/* this line will solve your error */

event.persist();
console.log(event);
}

 const App =()=>{
  const  handleKeyPress = ({ nativeEvent: { key: keyValue } }) => {
      console.log(keyValue);
      if(keyValue === 'Enter')
      {
        console.log("enter");
      }
  };
  return(
    <View>
         <TextInput
            placeholder="Your Password"
            placeholderTextColor="#666666"
            style={styles.inputSearch}
            // onEndEditing={(e)=>handleValidUser(e.nativeEvent.text)}
            onKeyPress={handleKeyPress}
          />
    </View>
  )
}
Related