📌  相关文章
📜  反应滚动到 div 的底部 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:37.252000             🧑  作者: Mango

代码示例1
import React, { useEffect, useRef } from 'react'

const Messages = ({ messages }) => {

  const messagesEndRef = useRef(null)

  const scrollToBottom = () => {
    messagesEndRef.current?.scrollIntoView({ behavior: "smooth" })
  }

  useEffect(() => {
    scrollToBottom()
  }, [messages]);

  return (
    
{messages.map(message => )}
) }