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

190
Visualizações
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 Respostas
Responde à pergunta

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