@mantine/hooks
Version:
A collection of 50+ hooks for state and UI management
26 lines (22 loc) • 778 B
JavaScript
'use client';
;
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