How to Keep a Chat Scrolled to the Newest Message in React
In a chat, new messages — and the words of an answer that streams in — appear at the bottom. Once the conversation is taller than its box, they appear below what people can see, unless the box scrolls with them. In React that takes an empty element at the end of the list, a ref to it, and one useEffect. This guide builds a list that grows like a streamed answer and compares it with and without the effect.
