mirror of
https://github.com/cheeaun/phanpy.git
synced 2024-12-24 19:28:15 +03:00
29 lines
559 B
JavaScript
29 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;
|
||
|
}
|