import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
/* eslint-disable react-hooks/exhaustive-deps */
import { useEffect, useState } from 'react';
var useNetworkStatus = function useNetworkStatus() {
  var _useState = useState(true),
    _useState2 = _slicedToArray(_useState, 2),
    isOnline = _useState2[0],
    setOnline = _useState2[1];
  var updateNetworkStatus = function updateNetworkStatus() {
    setOnline(navigator.onLine);
  };
  useEffect(function () {
    updateNetworkStatus();
  });
  useEffect(function () {
    window.addEventListener('load', updateNetworkStatus);
    window.addEventListener('online', updateNetworkStatus);
    window.addEventListener('offline', updateNetworkStatus);
    return function () {
      window.removeEventListener('load', updateNetworkStatus);
      window.removeEventListener('online', updateNetworkStatus);
      window.removeEventListener('offline', updateNetworkStatus);
    };
  }, [navigator.onLine]);
  return {
    isOnline: isOnline
  };
};
export default useNetworkStatus;