react 实现聊天界面,发送消息自动到底部
<div style={{ float:"left", clear: "both" }} ref={(el) => { this.messagesEnd = el; }}> </div>
scrollToBottom = () => { this.messagesEnd.scrollIntoView({ behavior: "auto" }); }
componentDidUpdate(prevProps, prevState, snapshot) { const { message } = this.state; this.scrollToBottom(); }
componentDidMount() { this.scrollToBottom(); }