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

62
Visualizações
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 Respostas
Responde à pergunta

0

Change setStorageId to setPage in your SelectDropDown component

about 4 years ago · Juan Pablo Isaza Relatório

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 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