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

258
Vistas
Cannot set properties of null in React

I have two elements that are supposed to appear depending on whether the condition is true or false but on one of them I need to use useRef hook but it doesn't work. Even though the element sometimes renders first, I still get the error Cannot set properties of null. I need to edit the second element's value when it renders with its reference but the code crashes so I can't do anything. Code looks like this:

inputRef.current.value="Some text"
{condition ? <SomeOtherComponent /> : <input type="text" ref={inputRef} />}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You have few options to fix that

  1. Remove ref on input and set value directly by value={'Some text'}.
  2. Render input and leave ref as it's but hide input by css based on condition.
  3. Create useEffect with listener on condition and when condition is falsy set the current.value.
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