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

160
Views
How to avoid async event handlers order messed

I struggle to find a way of having a guarantee that I have the right data after some async functions are called. I have a list of elements with an async onclick handler for each element. I have a slider which opens when an element is clicked and is populated asynchronously with some data.

const onClickElement = async () => {
    // open slider
    // await fetch data to display 
}

On slider close I have some async functionality to delete the data from the slider.

const onSliderClose = aync () => {
   // await async clear data 1
   // await async clear data 2
}

If I click close slider and immediately after, I click another element to reopen the slider,the new data is fetched before the slider onSliderClose handler finishes. The on close slider functionality resumes and is clearing all the previoualy fetched data. I am using react and redux for data storing. Thanks!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use await with async!

const onClickElement = async () => {
    // open slider
    // fetch data to display 
await fetchData()
}

Or alternative

const onClickElement = async () => {
        // open slider
        // fetch data to display 

    }

    onClickElement.then( () => {
    //Do what you have to do here
    })
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!