import { useState as i, useEffect as d, useRef as w } from "react";
const m = (t, r, { serialize: c = JSON.stringify, deserialize: s = JSON.parse } = {}) => {
  const [o, f] = i(
    r instanceof Function ? r() : r
  ), [u, a] = i(!1);
  d(() => {
    if (!(typeof window > "u"))
      try {
        const e = window.localStorage.getItem(t);
        e && f(s(e)), a(!0);
      } catch {
        a(!0);
      }
  }, [t, s]);
  const n = w(t);
  return d(() => {
    if (!(typeof window > "u" || !u))
      try {
        n.current !== t && window.localStorage.removeItem(n.current), n.current = t, window.localStorage.setItem(t, c(o));
      } catch {
      }
  }, [o, c, t, u]), [o, f];
};
export {
  m as default
};
//# sourceMappingURL=use-localstorage.js.map
