How to get focus from one textinput to another textinput?

Viewed 180

I have created a custom text input, suppose it to be Now I want to make user to get focused from one textinput to another. Make it as from

let {login,pass}=useRef(null)
<MyTextInput placeholder'login' ref={login} onSubmitEditing={()=>pass.focus()}/> 
<MyTextInput placeholder='password' ref={pass}/>

Now i am working with functional components in react native And I have tried adding ref to both of it as above. But I am getting error as cannot cannot read property focus of undefined.

Can anyone help me adding focus with this kind of textinputs?

1 Answers

Here is a simple snippet that should work in your case assuming your custom MyTextInput supports the same props as TextInput

export default function App() {
  const useranme = React.useRef(null)
  const password = React.useRef(null)
  return (
    <View>
      <MyTextInput onSubmitEditing={()=>password.current.focus()} ref={useranme} />
      <MyTextInput ref={password} />
    </View>
  );
}
Related