Files
GovAI/apps/web/src/hooks/use-scroll-bottom.ts
T
2026-06-15 23:48:37 +08:00

23 lines
527 B
TypeScript

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