Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

164
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda