Files
emaui/node_modules/@mantine/hooks/cjs/use-throttled-value/use-throttled-value.cjs
2026-05-29 15:23:46 +03:00

26 lines
778 B
JavaScript

'use client';
'use strict';
var React = require('react');
var 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;
//# sourceMappingURL=use-throttled-value.cjs.map