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
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 answers
Answer question

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 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!