'use strict';

var slicedToArray = require('../../slicedToArray-BcL7fKuL.js');
var react = require('react');
var ramda = require('ramda');
require('axios');
require('../../initializers/constants.js');
var utils_general = require('../../utils/general.js');
require('../../utils/dayjs.js');
require('../../utils/createSubscription.js');
require('dayjs');
require('i18next');
require('yup');
require('../../mixpanel.module-ajRn5e0J.js');
require('@bigbinary/neeto-cist');
require('../../unsupportedIterableToArray-BoHMiKNA.js');
require('../../objectWithoutProperties-wSsbHFcG.js');
require('../../index-BskY8dVw.js');
require('../../defineProperty-lChFfVqi.js');
require('../../typeof-D4ZZ_FlZ.js');
require('@bigbinary/neetoui/Toastr');
require('qs');
require('../../toConsumableArray-tBKHqzE3.js');
require('@rails/actioncable');

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)) {
        utils_general.removeFromLocalStorage(key);
      } else {
        utils_general.setToLocalStorage(key, newValue);
      }
      return newValue;
    });
  };
  return [storedValue, setValue];
};

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