Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

70
Views
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 answers
Answer question

0

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

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!