mirror of
https://github.com/cheeaun/phanpy.git
synced 2024-12-24 03:08:13 +03:00
5ab0ea1b59
In the end, only used one hook out of so many hooks
28 lines
559 B
JavaScript
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;
|
|
}
|