From 7d41de1303fb21049829749f7295e8dda923bd38 Mon Sep 17 00:00:00 2001 From: Or Halimi Date: Sat, 18 Jun 2022 17:15:04 +0300 Subject: [PATCH] Use limitToLast instead of limit in the query Prevent awkwardness when the db will have more than 25 documents. Getting the last N documents while maintaining ASC order. --- src/App.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/App.js b/src/App.js index d7c9417..858881c 100644 --- a/src/App.js +++ b/src/App.js @@ -63,7 +63,7 @@ function SignOut() { function ChatRoom() { const dummy = useRef(); const messagesRef = firestore.collection('messages'); - const query = messagesRef.orderBy('createdAt').limit(25); + const query = messagesRef.orderBy('createdAt').limitToLast(25); const [messages] = useCollectionData(query, { idField: 'id' });