import c from "../../../../rc-util/es/raf.mjs";
import * as a from "react";
import { useRef as n } from "react";
function d(f) {
  const [l, s] = a.useState(f), r = n(null), e = n([]), t = n(!1);
  a.useEffect(() => (t.current = !1, () => {
    t.current = !0, c.cancel(r.current), r.current = null;
  }), []);
  function o(m) {
    t.current || (r.current === null && (e.current = [], r.current = c(() => {
      r.current = null, s((i) => {
        let u = i;
        return e.current.forEach((p) => {
          u = p(u);
        }), u;
      });
    })), e.current.push(m));
  }
  return [l, o];
}
export {
  d as default
};
