skip to Main Content

I’m not able to find this anywhere. I have code like this:

const Component = () => {

  const handleKeyPress = (event) => {
    const key = event.nativeEvent.key.toLowerCase();
    console.log({key});
  };

  return (
    <TextInput
        onKeyPress={handleKeyPress}
        ...
    />
  )
}

What is the type of event parameter? In ReactJS I would use KeyboardEvent<HTMLInputElement> what is the equivalent in React-Native?

2

Answers


  1. Try using NativeSyntheticEvent and TextInputKeyPressEventData

    const handleKeyPress = (event: NativeSyntheticEvent<TextInputKeyPressEventData>) => {
    const key = event.nativeEvent.key.toLowerCase();
    console.log({ key });
    
    Login or Signup to reply.
  2. const handleKeyPress = (event: KeyboardEvent<TextInput>) => { 
    

    I hope this would help you.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search