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

293
Visualizações
How to use promises in javascript ? Basic Promise in Javascript

I am using redux. I want to perform a certain network call after updating store. I wrote promise for this as -

let promise=new Promise(function(resolve,reject){
updateStore() //separate method which updates the store.
}).then(()=>{    
 //Netowrk call
 //axios code
});

I am getting a syntax error here : Declaration or statement expected.

What should be the way of performing this activity?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You Can but not sure why you would want to use promise here? What are we waiting on?

function updateStore() {
   console.log("updating");
}

let promise=new Promise(function(resolve,reject){
  console.log('update')
  resolve( updateStore() ) //separate method which updates the store.
}).then(()=>{
  console.log('now network')    
 //Netowrk call
 //axios code
});
Using promise

Might be better served just to use a function.

function update_store(callback) {
   console.log("update store");
   callback(); /* or setTimeout( callback ); */
}

function now_network() {
   console.log("update network");
}

update_store(now_network);
Using callback

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