UNPKG

@mantine/hooks

Version:

A collection of 50+ hooks for state and UI management

21 lines (20 loc) 804 B
"use client"; import { useThrottledCallbackWithClearTimeout } from "../use-throttled-callback/use-throttled-callback.mjs"; import { useEffect, useRef, useState } from "react"; //#region packages/@mantine/hooks/src/use-throttled-value/use-throttled-value.ts 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; } //#endregion export { useThrottledValue }; //# sourceMappingURL=use-throttled-value.mjs.map