parent
d6b0187d8b
commit
b3f3586b31
@ -0,0 +1,27 @@ |
|||||||
|
import { |
||||||
|
useEffect, |
||||||
|
useRef, |
||||||
|
useState, |
||||||
|
} from 'react' |
||||||
|
|
||||||
|
export const useScroll = (deps: any) => { |
||||||
|
const ref = useRef<HTMLDivElement | null>(null) |
||||||
|
|
||||||
|
const [hasRefScroll, setRefScroll] = useState(false) |
||||||
|
|
||||||
|
useEffect(() => { |
||||||
|
const { |
||||||
|
clientHeight = 0, |
||||||
|
scrollHeight = 0, |
||||||
|
} = ref.current || {} |
||||||
|
const hasScroll = scrollHeight > clientHeight |
||||||
|
|
||||||
|
setRefScroll(hasScroll) |
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [ref, ...deps]) |
||||||
|
|
||||||
|
return { |
||||||
|
hasScroll: hasRefScroll, |
||||||
|
ref, |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue