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

196
Visualizações
Is there a way to render page only after updating infos ? | Ionic - React

I have some troubles with Async functions.
This is not the same as : This question

I'll do my best to explain. So I try to retrieve data from a Firebase Database.
I can upload data to the database without any problem. I can retrieve them too.

"So where is your issue ?" - probably you behind your screen

My issue is showing the data I retrieve from the database. Here is some code :

const [messages,setMessages] = useState<Message[]>([]);

  useIonViewWillEnter(() => {
    const msgs = getMessagesFromDB().then((data)=>{
      setMessages(data);
    });
   setBusy(false)
 });

And on another file :

export const getMessagesFromDB = async () : Promise<Message[]> => {
    const ref = await firebase.default.database().ref('message');
    try{
        ref.on('value', (snapshot) => {
            const data = snapshot.val();
            const current : Message = data['-Mv4-nZYSk9PoE_cwkWw'][0];
           
            setMessages(current);
            return current;
        });
    }catch (e) {
        throw e; 
    }
    return getMessages();
    
};

Here is my issue, if I do a console.log(data), I see my data from the database.
But I use messages on my page, and nothing show up:

 {busy ? <IonSpinner/> :  messages.map(m => <MessageListItem key={m.id} message={m} />)}

Do you know how can I wait for data ?

about 4 years ago · Juan Pablo Isaza
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