Files
medusa-store/packages/admin-ui/ui/src/hooks/use-scroll.ts
2023-03-13 14:02:20 +01:00

21 lines
440 B
TypeScript

import { useState } from "react"
type useScrollProps = {
threshold?: number
}
export const useScroll = ({ threshold = 0 }: useScrollProps) => {
const [isScrolled, setIsScrolled] = useState(false)
const scrollListener = (e) => {
const currentScrollY = e.target.scrollTop
if (currentScrollY > threshold) {
setIsScrolled(true)
} else {
setIsScrolled(false)
}
}
return { isScrolled, scrollListener }
}