Download src/hooks/useScrollToBottom.ts from IOE-IFAD/test: direct link, hf CLI and curl.
- Browser
- Download file 620 Bytes
-
https://huggingface.co/spaces/IOE-IFAD/test/resolve/main/src/hooks/useScrollToBottom.ts
- Command line
-
hf download hf://spaces/IOE-IFAD/test/src/hooks/useScrollToBottom.ts
-
curl -L -o useScrollToBottom.ts https://huggingface.co/spaces/IOE-IFAD/test/resolve/main/src/hooks/useScrollToBottom.ts
620 Bytes
| 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 }; | |
| }; | |