Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

168
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda