import { useState } from 'react';
import { inBrowser } from '../utils';
import useEventListener from './use-event-listener';

function useWindowSize() {
  var _useState = useState(inBrowser ? window.innerWidth : 0),
      width = _useState[0],
      setWidth = _useState[1];

  var _useState2 = useState(inBrowser ? window.innerHeight : 0),
      height = _useState2[0],
      setHeight = _useState2[1];

  var onResize = function onResize() {
    setWidth(window.innerWidth);
    setHeight(window.innerHeight);
  };

  useEventListener('resize', onResize);
  useEventListener('orientationchange', onResize);
  return {
    width: width,
    height: height
  };
}

export default useWindowSize;