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

24 lines
741 B
JavaScript

'use client';
import { useState, useRef, useEffect } from 'react';
import { useThrottledCallbackWithClearTimeout } from '../use-throttled-callback/use-throttled-callback.mjs';
function useThrottledValue(value, wait) {
const [throttledValue, setThrottledValue] = useState(value);
const valueRef = useRef(value);
const [throttledSetValue, clearTimeout] = useThrottledCallbackWithClearTimeout(
setThrottledValue,
wait
);
useEffect(() => {
if (value !== valueRef.current) {
valueRef.current = value;
throttledSetValue(value);
}
}, [throttledSetValue, value]);
useEffect(() => clearTimeout, []);
return throttledValue;
}
export { useThrottledValue };
//# sourceMappingURL=use-throttled-value.mjs.map