import { useState, useEffect } from 'react';

export default function useWindowDimensions() {
  const getWindowDimensions = () => {
    const { innerWidth: width, innerHeight: height } = window;

    return { width, height };
  };
  const [windowDimensions, setWindowDimensions] = useState(getWindowDimensions());

  useEffect(() => {
    const onRecize = () => setWindowDimensions(getWindowDimensions());

    window.addEventListener('resize', onRecize);

    return () => window.removeEventListener('resize', onRecize);
  }, []);

  return windowDimensions;
}
