Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | "use client";
import type { UIMessage } from "ai";
import { useEffect, type RefObject } from "react";
export function useChatAutoScroll(
containerRef: RefObject<HTMLElement | null>,
messages: UIMessage[],
isStreaming: boolean,
) {
useEffect(() => {
const container = containerRef.current;
if (!container) return;
container.scrollTo({
top: container.scrollHeight,
behavior: isStreaming ? "auto" : "smooth",
});
}, [containerRef, isStreaming, messages]);
}
|