import { useState as S, useRef as b, useCallback as h } from "react";
function R(t, m, l) {
  let [s, i] = S(t || m), u = b(t !== void 0), f = u.current, e = t !== void 0, n = b(s);
  f !== e && console.warn(`WARN: A component changed from ${f ? "controlled" : "uncontrolled"} to ${e ? "controlled" : "uncontrolled"}.`), u.current = e;
  let $ = h((r, ...a) => {
    let d = (o, ...c) => {
      l && (Object.is(n.current, o) || l(o, ...c)), e || (n.current = o);
    };
    typeof r == "function" ? (console.warn("We can not support a function callback. See Github Issues for details https://github.com/adobe/react-spectrum/issues/2320"), i((c, ...C) => {
      let p = r(e ? n.current : c, ...C);
      return d(p, ...a), e ? c : p;
    })) : (e || i(r), d(r, ...a));
  }, [
    e,
    l
  ]);
  return e ? n.current = t : t = s, [
    t,
    $
  ];
}
export {
  R as useControlledState
};
//# sourceMappingURL=module.es.js.map
