"use client";
import { useEffect, useState } from "react";

const useWindowSize = () => {
    const [size, setSize] = useState<[number, number]>([0, 0]);

    useEffect(() => {
        if (typeof window === "undefined") return;

        const updateSize = () => {
            setSize([window.innerWidth, window.innerHeight]);
        };

        window.addEventListener("resize", updateSize);
        window.addEventListener("load", updateSize);
        updateSize();

        return () => {
            window.removeEventListener("load", updateSize);
            window.removeEventListener("resize", updateSize);
        };
    }, []);

    return size;
};

export default useWindowSize;
