import { useState as i, useRef as l, useEffect as f } from "react";
function T(t, u, r) {
  const [c, n] = i(t), e = l(null);
  return f(() => {
    const o = t;
    r && !e.current && (e.current = setTimeout(() => {
      n(o), e.current = null;
    }, r));
    const s = setTimeout(() => {
      e.current && (clearTimeout(e.current), e.current = null), n(t);
    }, u);
    return () => {
      clearTimeout(s);
    };
  }, [t, u, r]), c;
}
export {
  T as useDebounce
};
