Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

221
Visualizações
React Native TextInput focus

I am fairly new in react native( "react-native": "0.65.1"). When I tried to use TextInput component I get ["No Command found with name "focus"][1]. I did not understood the problem. Here my code:

  const [text, setText] = useState('');
<TextInput
            style={{height: 40}}
            placeholder="Enter name"
            onChangeText={text => setText(text)}
            defaultValue={text}
          />

Can anybody help me for understanding the problem? Thank you! [1]: https://i.stack.imgur.com/FLdxK.png

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Accessing the native element in react native works differently.

  1. First you need to create a React.ref that will hold the native element functions.
  2. Then you pass that variable to your element

So to access the focus function of a textinput element you would do something like this

//code before your return your jsx
const textInputRef = useRef({});
...
//your other variables and stuff
...
return (
    ....
    <TextInput
            style={{height: 40}}
            placeholder="Enter name"
            onChangeText={text => setText(text)}
            defaultValue={text}
            ref={textInputRef}
          />
)

You may save yourself some debugging time if you verify that the focus function exists on your ref

// one liner
textInputRef.current.focus.?()
//verbose
if(textInputRef.current.focus)
  textInputRef.current.focus
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda