Returns a DebouncedFunction
. Accepts custom delay in milliseconds and immediate boolean for leading/trailing execution.
function debounce<T extends (...args: any[]) => any>(
func: T,
delay: number,
immediate?: boolean
)
If immediate
is true
, the function will execute immediately on the first call. The function will not execute if called again until the provided number of milliseconds have passed.
If immediate
is false
, the function will not execute when called until the provided number of milliseconds have passed. If the function is called again before the time has passed, the previous call is forgotten the timer starts over.