init
This commit is contained in:
commit
a04776256d
56 changed files with 6808 additions and 0 deletions
16
lib/hooks/use-scroll.ts
Normal file
16
lib/hooks/use-scroll.ts
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import { useCallback, useEffect, useState } from "react";
|
||||
|
||||
export default function useScroll(threshold: number) {
|
||||
const [scrolled, setScrolled] = useState(false);
|
||||
|
||||
const onScroll = useCallback(() => {
|
||||
setScrolled(window.pageYOffset > threshold);
|
||||
}, [threshold]);
|
||||
|
||||
useEffect(() => {
|
||||
window.addEventListener("scroll", onScroll);
|
||||
return () => window.removeEventListener("scroll", onScroll);
|
||||
}, [onScroll]);
|
||||
|
||||
return scrolled;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue