import { useEffect, useState } from "react";

const useResize = () => {
  //   const isBrowser = typeof window !== "undefined";
  const [dimensions, setDimensions] = useState({
    width: window.innerWidth,
    height: window.innerHeight,
  });

  const handleWindowResize = () => {
    setDimensions({
      width: window.innerWidth,
      height: window.innerHeight,
    });
  };

  useEffect(() => {
    window.addEventListener("resize", handleWindowResize);
    handleWindowResize();
    return () => {
      window.removeEventListener("resize", handleWindowResize);
    };
  }, [setDimensions]);

  return {
    dimensions,
  };
};

export default useResize;
