Poonam
Poonam

Reputation: 113

How to Detect Backspace character in TextInput with react native

How to detect typed character is the backspace/delete

if (e.nativeEvent.key === 'Backspace') 

tried this but not working

Upvotes: 10

Views: 12637

Answers (1)

Samuli Hakoniemi
Samuli Hakoniemi

Reputation: 19049

https://facebook.github.io/react-native/docs/textinput#onkeypress

<TextInput
  onKeyPress={({ nativeEvent }) => {
    if (nativeEvent.key === 'Backspace') {
      ...doTheMagic();...
    }
  }}
/>

Live example: https://snack.expo.io/@zvona/backspace

Upvotes: 35

Related Questions