in src/hooks/useScrollHash.ts [26:46]
export function useScrollHash() {
const history = useHistory();
const handleScroll = () => {
const currentHash = window.location.hash;
const scrollPosition = window.scrollY;
const scrollIdSelect: NodeListOf<HTMLElement> =
document.querySelectorAll(".scroll-id-select");
const id = findHighId(scrollPosition, scrollIdSelect);
if (id && "#" + id != currentHash) {
history.replace({ hash: id });
}
};
const throttleFunc = throttle(handleScroll, 10);
useEffect(() => {
window.addEventListener("scroll", throttleFunc);
return () => {
window.removeEventListener("scroll", throttleFunc);
};
}, []);
}