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

162
Visualizações
React run a specific function after every function

Let's say I have multiple functions that change data in the back-end and I want to have a page with CRUD features. On that page I want to be able to create/delete the data and display it. Every time I create an item or delete one, I fetch the data and display it, so it stays updated.

Currently, in the create/delete functions I also call fetch at the end. But if I have multiple functions which modify the data I need to call fetch in every function.

const createItem = async () => {
  await axios.post(...);
  const newData = await axios.get(...);
  setData(newData);
}

const deleteItem = async () => {
  await axios.delete(...);
  const newData = await axios.get(...);
  setData(newData);
}

Is there any way I can call a fetch data function after every function that changes data?

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

0

You could move the newData / setData(newData) to a separate function and call that after createItem and deleteItem have successfully completed.

If you create new functions that need to get the new data after completing you can use it there too.

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