"use client"; import { useCallback, useEffect, useRef } from "react"; /** * 自动滚动到容器底部。 * 当 deps 变化时触发滚动(通常传入 messages 数组)。 */ export function useScrollToBottom(deps: unknown[]) { const ref = useRef(null); const scrollToBottom = useCallback(() => { ref.current?.scrollIntoView({ behavior: "smooth" }); }, []); useEffect(() => { scrollToBottom(); // eslint-disable-next-line react-hooks/exhaustive-deps }, deps); return ref; }