import { useRef as i, useCallback as o } from "react";
const u = (r, c, e = !1) => {
  const t = i(-1), n = o(
    (...s) => {
      a(), t.current = requestAnimationFrame(() => {
        r(...s), e && n(...s);
      });
    },
    [...c, e]
  ), a = o(() => {
    cancelAnimationFrame(t.current);
  }, []);
  return { start: n, stop: a };
};
export {
  u as default
};
