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

64
Vistas
Losing state inside eventHandler
const [page,setPage] = useState()

console.log(page) // gives "Page1" upon state update
const onValueChange = (event) => {
    console.log(page); //gives undefined upon state update
};

<Input
onChange={(e) => onValueChange(e)}         
/>

<SelectDropdown
onChange={() => setPage("Page1")}
value={page}
/>

Above code is a brief example on how I cant access the state "page" inside the function from an eventHandler, how is it possible to access the state inside onValueChange().

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

0

Change setStorageId to setPage in your SelectDropDown component

about 4 years ago · Juan Pablo Isaza Denunciar

0

Your could should work as it is normally. An explanation of why you getting undefined in onValueChange is that you are changing the value of the Input before changing SelectDropdown's value, in witch case it's normal, because this line :

const [page,setPage] = useState()

sets page to undifined. You can test it here on this CodeSandbox I just created.

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