INNER CODE UNIT · TypeScript
useScrollToBottom
e2b-dev/surf · components/use-scroll-to-bottom.ts:3
export function useScrollToBottom<T extends HTMLElement = HTMLDivElement>(): [
RefObject<T>,
RefObject<T>,
] {
const containerRef = useRef<T>(null);
const endRef = useRef<T>(null);
useEffect(() => {
const container = containerRef.current;
const end = endRef.current;
if (container && end) {
const observer = new MutationObserver(() => {
end.scrollIntoView({ behavior: "smooth" });
});
observer.observe(container, {
childList: true,