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

93
Views
Reactjs state doesn't updating after async await API call

I am a beginner in React. I have a setState from my async await function which calls an API. after calling the API, there are some issues happen since my state doesn't update immediately. How can I await my setState funcion so that it changes when the latest data was pulled?

Here is my whole function.

const getTimeLogsFromAPI = async () => {        
        const person_id = props.profile.basic_information.primary_information.id;
        const uuid = props.profile.basic_information.primary_information.uuid_qrcode;
        const new_format_date = dateFormatter(new Date(state.selectedDate));
        const response = await fetch(`${getDjangoApiHost()}/api/jobnet_app/pass_check/${uuid}/?specific_month=${new_format_date}&person_id=${person_id}`);
        const dataTimeLogs = await response.json();
        if (dataTimeLogs) {
            await setTimeLogs(dataTimeLogs)            
        }
        if (timeLogs) {
            await setShowDTR(true);
        }
    }  
about 4 years ago · Juan Pablo Isaza
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!