I am using react native with Firebase Realtime Database. Testing a simple chat app and I am fetching the chats like so:
this.friendChatRef = this.db.ref('messages/' + this.chat_id + '/' + this.friend_id)
const friendChatRef = this.friendChatRef.limitToLast(9)
const fcrp = friendChatRef.once('value')
The goal is to always get the last 9 messages from the conversation when the component/view mounts.
The problem is that It will fetch 9 chats but they are not the latest in any way. I can add 10+ new messages but they will never be fetched until I add this:
friendChatRef.keepSynced(true)
Then every time I access the chat it will fetch the latest 9 messages.
Why do we have to use keepSynched? I thought persistence is just for the offline data caching but it always checks if the cached data is outdated or not every time you create a ref and fetch the data?
Is there any way to keep the persistence and not use keepSynched to get the latest data?