{"version":3,"file":"use-throttled-value.mjs","names":[],"sources":["../../src/use-throttled-value/use-throttled-value.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\nimport { useThrottledCallbackWithClearTimeout } from '../use-throttled-callback/use-throttled-callback';\n\nexport function useThrottledValue<T>(value: T, wait: number) {\n  const [throttledValue, setThrottledValue] = useState(value);\n  const valueRef = useRef(value);\n\n  const [throttledSetValue, clearTimeout] = useThrottledCallbackWithClearTimeout(\n    setThrottledValue,\n    wait\n  );\n\n  useEffect(() => {\n    if (value !== valueRef.current) {\n      valueRef.current = value;\n      throttledSetValue(value);\n    }\n  }, [throttledSetValue, value]);\n\n  useEffect(() => clearTimeout, []);\n\n  return throttledValue;\n}\n"],"mappings":";;;;AAGA,SAAgB,kBAAqB,OAAU,MAAc;CAC3D,MAAM,CAAC,gBAAgB,qBAAqB,SAAS,KAAK;CAC1D,MAAM,WAAW,OAAO,KAAK;CAE7B,MAAM,CAAC,mBAAmB,gBAAgB,qCACxC,mBACA,IACF;CAEA,gBAAgB;EACd,IAAI,UAAU,SAAS,SAAS;GAC9B,SAAS,UAAU;GACnB,kBAAkB,KAAK;EACzB;CACF,GAAG,CAAC,mBAAmB,KAAK,CAAC;CAE7B,gBAAgB,cAAc,CAAC,CAAC;CAEhC,OAAO;AACT"}