"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const React = require("react");
const useThrottledCallback = require("../use-throttled-callback/use-throttled-callback.cjs");
function useThrottledValue(value, wait) {
  const [throttledValue, setThrottledValue] = React.useState(value);
  const valueRef = React.useRef(value);
  const [throttledSetValue, clearTimeout] = useThrottledCallback.useThrottledCallbackWithClearTimeout(
    setThrottledValue,
    wait
  );
  React.useEffect(() => {
    if (value !== valueRef.current) {
      valueRef.current = value;
      throttledSetValue(value);
    }
  }, [throttledSetValue, value]);
  React.useEffect(() => clearTimeout, []);
  return throttledValue;
}
exports.useThrottledValue = useThrottledValue;
