import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
/* "use client" */;

/* eslint-disable @typescript-eslint/ban-types */

import * as React from "react";
export default function useLocalStorage(key, initialValue) {
  var _React$useState = React.useState(function () {
      try {
        var item = typeof window !== "undefined" && window.localStorage.getItem(key);
        return item ? item : initialValue;
      } catch (error) {
        return initialValue;
      }
    }),
    _React$useState2 = _slicedToArray(_React$useState, 2),
    storedValue = _React$useState2[0],
    setStoredValue = _React$useState2[1];
  var setValue = function setValue(value) {
    try {
      var valueToStore = value instanceof Function ? value(storedValue) : value;
      setStoredValue(valueToStore);
      window.localStorage.setItem(key, valueToStore);
    } catch (error) {
      console.log(error);
    }
  };
  return [storedValue, setValue];
}