Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

220
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda