Home > Blockchain >  How to focus TextInput after component mount ( initialize with the TextInput focused ) - React Nativ
How to focus TextInput after component mount ( initialize with the TextInput focused ) - React Nativ

Time:10-02

How do I open a stateless component with the TextInput already in foucs?

Thank you all!

CodePudding user response:

If you only want the TextInput field focused on component mount, then you can use the autoFocus prop of a TextInput component e.g.

<TextInput
   autoFocus={true}
/>

CodePudding user response:

Hi Túlio here is the code and you can also check the live working example I've added in this link --> Snack Example

export default function App() {
  React.useEffect(()=>{
    
    focusRef.current.focus()
  },[])
  const focusRef=React.useRef()
  return (
    <View style={styles.container}>
    <TextInput
    placeholder="FirstTextInput"
    returnKeyType="next"
    ref={focusRef}
    blurOnSubmit={false}
    style={{padding:10}}
/>
 
    </View>
  );
}
  • Related