0

This is my code React native: import React from "react"; import { View, StyleSheet, TextInput } from "react-native";

const UselessTextInput = () => {
  const [text, onChangeText] = React.useState("");
  const [number, onChangeNumber] = React.useState(null);

  return (
    <View>
      <TextInput
        style={styles.input}
        onChangeText={onChangeText}
        value={text}
      />
    </View>
  );
};

const styles = StyleSheet.create({
  input: {
    height: 40,
    margin: 12,
    borderWidth: 1,
  },
});

export default UselessTextInput;

Link expo: https://snack.expo.dev/@robocon321/textinput

robocon321
  • 363
  • 5
  • 8

1 Answers1

1

use onKeyPress

onKeyPress={({ nativeEvent }) => {
  if (nativeEvent.key === 'Backspace') {
     alert("Backspace is pressed")
  } 
}}

try snack here

work on ios & android

note on android!

Note: on Android only the inputs from soft keyboard are handled, not the hardware keyboard inputs.

soft keyboard (onscreen keyboard or software keyboard) like keyboard in the screen of phone or tablet.
hardware keyboard (external keyboard) like keyboard with USB (android support that) but you can ignore it.

Ahmed Gaber
  • 3,384
  • 2
  • 12
  • 18