I want to build a chat system and automatically scroll to the bottom when entering the window and when new messages come in. How do you automatically scroll to the bottom of
Using React.createRef()
React.createRef()
class MessageBox extends Component { constructor(props) { super(props) this.boxRef = React.createRef() } scrollToBottom = () => { this.boxRef.current.scrollTop = this.boxRef.current.scrollHeight } componentDidUpdate = () => { this.scrollToBottom() } render() { return ( ) } }