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

214
Views
useEffect is not immediate in ReactJS also if I use an async function

Basically every time I do a operation to my database (sqlite3) it does not render immediately on the page, but I have to click on some other component to update or I have to refresh the page/reset the server

This is the snippet I quite use in every page component:

const fetchData= async()=>{
        let updatedVector= await API.getUpdate();
        for (let i = 0;i<props.courses.length;i++){
            for (let j=0;j<updatedVector.length;j++){
                if(props.courses[i].code===updatedVector[j].code){
                    props.courses[i].current= await API.getSpecificData(props.courses[i].code);
                }
            }
        }
    }

    //
    useEffect(()=>{
        fetchData();
    },[fetchData])

It does update on the database but takes some time to update on the component, is there any way to update like in an immediate way? Or I have to refresh the application.


EDIT: I passed the setState too, but yet I have to click at least twice on the component link and then I have my update:

//get updates
    useEffect(()=>{
        console.log("triggered")
        const fetchData= async()=>{
            let updatedVector= await API.getUpdate();
            for (let i = 0;i<props.courses.length;i++){
                for (let j=0;j<updatedVector.length;j++){
                    if(props.courses[i].code===updatedVector[j].code){
                        props.courses[i].current= await API.getSpecificData(props.courses[i].code);
                    }
                }
            }
            props.setCourses(props.courses)
        }
        fetchData();
    },[fetchData])
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Is props.courses[i].current a useRef?

if so try using useState to handle your data, u won't have a re-render problem.

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!