saleor-dashboard/src/hooks/useWindowScroll.ts
Michał Droń d5c9a3dae8
Add trailing commas (#2062)
* Require trailing commas

* Add trailing commas

* Add trailing commas in testUtils dir

* Add trailing commas
2022-06-21 11:36:55 +02:00

24 lines
545 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;