I have a RN app that has a home screen with different chats. When the user taps on a chat, it’s messages are loaded from the local db and displayed. Like Whatsapp does, I want to preload messages and scroll to the last message before the screen is actually loaded. I have tried loading messages in useEffect
with an empty dependency array but the messages are shown after the screen is loaded. So the user sees a glitch. I want to avoid that glitch. I have also tried to use useFocusEffect
with no effect.
2
Answers
the way that I solved a similar problem, when I had it, was:
Put it simply. You have 2 screens. One for the loading and another that only appears when you finish loading everything.
Keep in mind this is a very simple approach using only
useEffect
anduseState
. There are, probably, more optimized ways to go about it.Try settimeout with useffect hook and loading usestate