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

198
Vistas
React Native: why are useState hooks sometimes undefined?

In my React Native app I have two components, A and B:

export const A = () => {
  const [text, setText] = useState('');
  return (
    <View>
      <B
        _text={text}
        _setText={setText}
      />
    </View>
  )
}

const B = ({_text, _setText}) => {
  console log(_text, _setText);
  ...
  ...
}

I console.log _text and _setText in B. This console.log gets called multiple times whenever I open the B component, and sometimes it logs both _text and _setText as undefined.

Does anyone know why this would be?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You're most likely rendering the B Component before the text state is updated. To fix it, check that it isn't null/empty:

export const A = () => {
  const [text, setText] = useState('');
  return (
    <View>
      {text ? <B
        _text={text}
        _setText={setText}
      /> : null}
    </View>
  )
}
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