Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

196
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda