File size: 620 Bytes
e454383
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { useEffect, useRef } from "react";

export const useScrollToBottom = () => {
  const scrollRef = useRef<HTMLDivElement>(null);

  const scrollToBottom = () => {
    if (scrollRef.current) {
      // Get the actual scrollable container
      const scrollContainer = scrollRef.current.querySelector(
        "[data-radix-scroll-area-viewport]"
      );
      if (scrollContainer) {
        const targetPosition = scrollContainer.scrollHeight;
        scrollContainer.scrollTo({
          top: targetPosition,
          behavior: "smooth",
        });
      }
    }
  };

  return { scrollRef, scrollToBottom };
};