Raw
1 import { useRef, useState } from "react"
2
3 export const useHandleTableScroll = () => {
4 const tableContainerRef = useRef<HTMLDivElement>(null)
5
6 // Listen for if the table container that has overflow-y: auto is scrolled, and if true set some state
7 const [isScrolled, setIsScrolled] = useState(false)
8
9 const handleScroll = () => {
10 if (tableContainerRef.current) {
11 setIsScrolled(
12 tableContainerRef.current.scrollTop > 0 &&
13 tableContainerRef.current.scrollTop <
14 tableContainerRef.current.scrollHeight
15 )
16 }
17 }
18
19 return {
20 tableContainerRef,
21 isScrolled,
22 handleScroll,
23 }
24 }