'use strict';

var slicedToArray = require('../../../slicedToArray-BcL7fKuL.js');
var React = require('react');
var ramda = require('ramda');
require('axios');
require('../../initializers/constants.js');
var v2_utils_general = require('../../utils/general.js');
require('../../utils/datetime.js');
require('../../utils/createSubscription.js');
require('dayjs');
require('i18next');
require('yup');
require('../../../lodash-Dn9Lp_19.js');
require('@bigbinary/neeto-cist');
require('@bigbinary/neeto-time-zones');
require('ua-parser-js');
require('../../utils/dayjs.js');
require('../../../unsupportedIterableToArray-BoHMiKNA.js');
require('../../../objectWithoutProperties-wSsbHFcG.js');
require('../../../asyncToGenerator-8vhqAwJl.js');
require('../../../defineProperty-lChFfVqi.js');
require('../../../typeof-D4ZZ_FlZ.js');
require('@bigbinary/neeto-atoms');
require('qs');
require('../../utils/constants.js');
require('../../utils/dayjsFormatOverrides/default.js');
require('../../utils/localePlugin.js');
require('@rails/actioncable');
require('../../../toConsumableArray-tBKHqzE3.js');
require('../../../createClass-B4XY44hG.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 = React.useState(function () {
      return getStorageValue(key, defaultValue);
    }),
    _useState2 = slicedToArray._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 (ramda.isNil(newValue)) {
        v2_utils_general.removeFromLocalStorage(key);
      } else {
        v2_utils_general.setToLocalStorage(key, newValue);
      }
      return newValue;
    });
  };
  return [storedValue, setValue];
};

module.exports = useLocalStorage;
//# sourceMappingURL=useLocalStorage.js.map
