UNPKG

@mantine/hooks

Version:

A collection of 50+ hooks for state and UI management

21 lines (20 loc) 868 B
"use client"; const require_use_throttled_callback = require("../use-throttled-callback/use-throttled-callback.cjs"); let react = require("react"); //#region packages/@mantine/hooks/src/use-throttled-value/use-throttled-value.ts function useThrottledValue(value, wait) { const [throttledValue, setThrottledValue] = (0, react.useState)(value); const valueRef = (0, react.useRef)(value); const [throttledSetValue, clearTimeout] = require_use_throttled_callback.useThrottledCallbackWithClearTimeout(setThrottledValue, wait); (0, react.useEffect)(() => { if (value !== valueRef.current) { valueRef.current = value; throttledSetValue(value); } }, [throttledSetValue, value]); (0, react.useEffect)(() => clearTimeout, []); return throttledValue; } //#endregion exports.useThrottledValue = useThrottledValue; //# sourceMappingURL=use-throttled-value.cjs.map