phanpy/src/utils/useWindowSize.js
Lim Chee Aun 5ab0ea1b59 Remove usehooks dep
In the end, only used one hook out of so many hooks
2024-06-27 22:05:16 +08:00

28 lines
559 B
JavaScript

import { useLayoutEffect, useState } from 'preact/hooks';
export default function useWindowSize() {
const [size, setSize] = useState({
width: null,
height: null,
});
useLayoutEffect(() => {
const handleResize = () => {
setSize({
width: window.innerWidth,
height: window.innerHeight,
});
};
handleResize();
window.addEventListener('resize', handleResize, {
passive: true,
});
return () => {
window.removeEventListener('resize', handleResize);
};
}, []);
return size;
}