mirror of
https://github.com/Tria-plc/emaui.git
synced 2026-08-27 22:30:56 +00:00
26 lines
778 B
JavaScript
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
|