Skip to content
Advertisement

React Native Text Input focus with useRef using Typescript

I have an issue with focusing the next input in React Native. I use just one input called GeneralTextInput.tsx in the whole app.

In this example I have 2 inputs ==> 1.Group Name, 2.Group Description

So I give some props in the parent to this component:

JavaScript

And this is my GeneralTextInput.tsx What should I give to the input as a ref and how should I focus on it?

JavaScript

Advertisement

Answer

You wrap GeneralTextInput with forwardRef:

JavaScript

Now in the parent component Define one useRef:

JavaScript

you have 2 generalInput. on first input

JavaScript

second GeneralInput will be as it is

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement