How to scroll to bottom in react?

前端 未结 19 908
执笔经年
执笔经年 2020-11-28 18:27

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

19条回答
  •  悲&欢浪女
    2020-11-28 19:04

    Full version (Typescript):

    import * as React from 'react'
    
    export class DivWithScrollHere extends React.Component {
    
      loading:any = React.createRef();
    
      componentDidMount() {
        this.loading.scrollIntoView(false);
      }
    
      render() {
    
        return (
          
    { this.loading = e; }}>
    ) } }

提交回复
热议问题