import { _ as _slicedToArray } from '../../../slicedToArray-DmsZvA_9.js';
import { useState } from 'react';
import { isNil } from 'ramda';
import 'axios';
import '../../initializers/constants.js';
import { removeFromLocalStorage, setToLocalStorage } from '../../utils/general.js';
import '../../utils/datetime.js';
import '../../utils/createSubscription.js';
import 'dayjs';
import 'i18next';
import 'yup';
import '../../../lodash-BmsmkciF.js';
import '@bigbinary/neeto-cist';
import '@bigbinary/neeto-time-zones';
import 'ua-parser-js';
import '../../utils/dayjs.js';
import '../../../unsupportedIterableToArray-Dqz8Y8_I.js';
import '../../../objectWithoutProperties-DN7d1SzH.js';
import '../../../asyncToGenerator-CPKhuIh2.js';
import '../../../defineProperty-Dcer7TUY.js';
import '../../../toPropertyKey-BAXkSB3z.js';
import '../../../typeof-D-UKOauR.js';
import '@bigbinary/neeto-atoms';
import 'qs';
import '../../utils/constants.js';
import '../../utils/dayjsFormatOverrides/default.js';
import '../../utils/localePlugin.js';
import '@rails/actioncable';
import '../../../toConsumableArray-B7CFjjkW.js';
import '../../../createClass-CuM_Q_Jb.js';

var getStorageValue = function getStorageValue(key, defaultValue) {
  try {
    var storedValue = localStorage.getItem(key);
    return storedValue ? JSON.parse(storedValue) : defaultValue;
  } catch (error) {
    logger.error(error);
    return defaultValue;
  }
};
var useLocalStorage = function useLocalStorage(key, defaultValue) {
  var _useState = useState(function () {
      return getStorageValue(key, defaultValue);
    }),
    _useState2 = _slicedToArray(_useState, 2),
    storedValue = _useState2[0],
    setStoredValue = _useState2[1];
  var setValue = function setValue(value) {
    return setStoredValue(function (prevStoredValue) {
      var newValue = typeof value === "function" ? value(prevStoredValue) : value;
      if (isNil(newValue)) {
        removeFromLocalStorage(key);
      } else {
        setToLocalStorage(key, newValue);
      }
      return newValue;
    });
  };
  return [storedValue, setValue];
};

export { useLocalStorage as default };
//# sourceMappingURL=useLocalStorage.js.map
