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

165
Views
is there a way to wait till a function runs before an axis patch call

I have a variable originalVar then I have another called updatedVar, when the user clicks a button originalVar needs to call a function - this function needs to set OriginalVar to updatedVar and then use axios patch to write it to db.

Do I need to use async or how would I do this to ensure this all updates because I need the originalVar to be updated to be used in another place ?

Sample code snippet:

const [saveButton,setSaveButton]= useState(false)
 
useEffect(()=>{
   if(saveButton)
      {
       setOriginalVar(UpdatedVar)
       //wait till this above statement runs then
       duplicateVar = originalVar
      }
    
}),[saveButton]

const finishButtonClick =() =>{
//do some logic 
setSaveButton(true) 
//wait till that finishes running and then,
axis.patch(blahblah,duplicateVar)
}
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

const finishButtonClick = async () =>{
    //do some logic 
    setSaveButton(true) 
    //wait till that finishes running and then,
    const data = await axis.patch(blahblah,holdVar)
    //This will wait for the above line to finish
}
about 4 years ago · Juan Pablo Isaza Report

0

   setOriginalVar(UpdatedVar)
   //wait till this above statement runs then
   duplicateVar = originalVar

What does setOriginalVar return? If it is a promise, you can do

   var p = setOriginalVar(UpdatedVar);
   //wait till this above statement runs then
   p.then(function(value) {
     duplicateVar = originalVar;
   });
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!