import { useEffect, useState } from "react";

type Size = { width: number; height: number };

export function useWindowSize(): Size {
  const [size, setSize] = useState<Size>({
    width: typeof window === "undefined" ? 1920 : window.innerWidth,
    height: typeof window === "undefined" ? 1080 : window.innerHeight,
  });

  useEffect(() => {
    function handle() {
      setSize({ width: window.innerWidth, height: window.innerHeight });
    }
    window.addEventListener("resize", handle);
    handle();
    return () => window.removeEventListener("resize", handle);
  }, []);

  return size;
}
