mirror of
https://github.com/simstudioai/sim.git
synced 2026-04-28 03:00:29 -04:00
* improvement(kb): removed zustand cache syncing in kb, added chunk text tokenizer * removed dead code * removed redundant hook * remove unused hook * remove alert notification and use simple error * added more popover actions * removed debug instrumentation * remove extraneous comments * removed unused handler
24 lines
548 B
TypeScript
24 lines
548 B
TypeScript
import { useEffect, useState } from 'react'
|
|
|
|
/**
|
|
* A hook that debounces a value by a specified delay
|
|
* @param value The value to debounce
|
|
* @param delay The delay in milliseconds
|
|
* @returns The debounced value
|
|
*/
|
|
export function useDebounce<T>(value: T, delay: number): T {
|
|
const [debouncedValue, setDebouncedValue] = useState<T>(value)
|
|
|
|
useEffect(() => {
|
|
const timer = setTimeout(() => {
|
|
setDebouncedValue(value)
|
|
}, delay)
|
|
|
|
return () => {
|
|
clearTimeout(timer)
|
|
}
|
|
}, [value, delay])
|
|
|
|
return debouncedValue
|
|
}
|