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; }