Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 733
Poonam Avatar asked Nov 14 '18 11:11

Poonam


1 Answers

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

like image 180
Samuli Hakoniemi Avatar answered Sep 27 '22 19:09

Samuli Hakoniemi