Files
medusa-store/packages/admin-next/dashboard/src/hooks/use-handle-table-scroll.tsx
2024-01-18 15:01:34 +01:00

25 lines
636 B
TypeScript

import { useRef, useState } from "react"
export const useHandleTableScroll = () => {
const tableContainerRef = useRef<HTMLDivElement>(null)
// Listen for if the table container that has overflow-y: auto is scrolled, and if true set some state
const [isScrolled, setIsScrolled] = useState(false)
const handleScroll = () => {
if (tableContainerRef.current) {
setIsScrolled(
tableContainerRef.current.scrollTop > 0 &&
tableContainerRef.current.scrollTop <
tableContainerRef.current.scrollHeight
)
}
}
return {
tableContainerRef,
isScrolled,
handleScroll,
}
}