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

192
Views
Navigation addListener does not executes after await action

I am listening to focus event on navigation in React native & using @react-navigation^5.x.x in componentDidMount. If only this action is written, then it works well and executes the code within it.

But in my case, I am fetching data from API (Also tried by mocking await) and using await before adding focus listener. It's not getting listened to for the first time. But when I go to another page and comes back, It starts working/executing.

Here's my code snippet.

async componentDidMount() {
    
    await new Promise(resolve => setTimeout(resolve, 3000)); // 3 sec

    navigation.addListener('focus', async (data) => {
        console.log('This block not works for first time when I come on page.')
    })

}

Edit - Even If I remove await and put the whole block in timeout, then also it stops executing the focus callback.

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

0

I don't think you can use async on the life cycle try this instead:

componentDidMount() {
    const getData = async (params) => {
        await new Promise(resolve => setTimeout(resolve, 3000)); // 3 sec

        navigation.addListener('focus', async (data) => {
            console.log('This block not works for first time when I come on page.')
        })

    }
    getData()
}
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!