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

200
Visualizações
firestore sub collection removes change listeners when limit is reached?

When data is added to a subcollection the real-time data snapshot is not getting triggered if the limit I set is reached. How to go around this?

I want the snapshot to display the last 25 newest texts. But since the limit is reached it just halts the function and I am stuck with the last 25 rendered and new ones don't show at all.

What is even worst about this if I reload the page to see if the function will render the new items after the limit has reached:

  • it doesn't it simply shows the 25 created.
  • it ignores any new items so the query is simply broken from that point up.

useEffect(() => {
    if (_globalContext.focus) {
      let collectionRef = collection(db, 'Chat', docId, 'messages');
      const querydata = query(collectionRef, orderBy('createdAt'), limit(25));
      const unsub = onSnapshot(querydata , (querySnapshot) => {

        console.log(querySnapshot, 'triggered');
        querySnapshot.forEach((doc) => {
          console.log(doc.data());
        });
      });
      setChats(data);
      return () => {
       unsub();
      };
    }
  }, [_globalContext.focus]);

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If you want to show the 25 most recent documents, you need to either sort on descending timestamp or limit to the *last 25 (instead of the first 25):

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