Is there a way to store all chat messages for a two way chat locally to reduce the lag between when the user hits the send button and when the chat message bubble displays on the UI? Specifically, I'm experiencing a delay of 1000-2000 milliseconds (sometimes longer depending on phone signal).
I’ve read about optimistic UI updates, where you show the chat message in the UI before it's actually written to the database, but I’m not sure how to do this properly.
Right now, my chat list view directly queries Firebase for messages. However, a better approach would be to link the list view to a local page state that stores a list of preloaded chat messages. When the user sends a message, it would do two things at once: write to the database and add the new message to the local list in the page state. This way, the message appears instantly in the UI without waiting for the database to update.
Any suggestions on how to best handle this and smooth out the user experience would be greatly appreciated. Thanks!