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

71
Visualizações
Variable is not updating data React

I have in my App.jsx a fetch to the backend to request the user data and then in a child component I use that info to show or not something (depending if we have user or not). With the React Dev Tools extension for Chrome, I can see that the variable has information, but I don't understand why my code is not working.

const [myEvents, setMyEvents] = useState(null)

const eventsFetch = async () => {

    // I use this conditional to wait until the backend response.
    if(user == null) {
        console.log('test')
        setTimeout(eventsFetch, 250)
    } else {
        const resEvents = await getAllEventsUser(user._id);
        setMyEvents(resEvents);
        
    }
}

useEffect(() => {
    setMenuHome(true);
    eventsFetch();
}, []);

The conditional is always going where the console.log is.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I had to add the variable user to the useEffect dependecy and now it's working

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