
* Add analysis tools * Use deep imports to reduce bundle size * Remove tslint config * Remove unused packages * Remove lodash-es references * Use root level mui imports * Remove mui from restricted imports
24 lines
544 B
TypeScript
24 lines
544 B
TypeScript
import throttle from "lodash/throttle";
|
|
import { useEffect, useState } from "react";
|
|
|
|
function getPosition() {
|
|
return {
|
|
x: window.pageXOffset,
|
|
y: window.pageYOffset
|
|
};
|
|
}
|
|
|
|
function useWindowScroll() {
|
|
const [scroll, setScroll] = useState(getPosition);
|
|
|
|
useEffect(() => {
|
|
const handleScroll = throttle(() => setScroll(getPosition()), 100);
|
|
|
|
window.addEventListener("scroll", handleScroll);
|
|
|
|
return () => window.removeEventListener("scroll", handleScroll);
|
|
}, []);
|
|
|
|
return scroll;
|
|
}
|
|
export default useWindowScroll;
|