debounce
Returns a debounced version of the given function, delaying its execution
until after wait milliseconds have passed since the last call.
- @param
callback- The function to debounce. - @param
wait- Delay in milliseconds beforecallbackis invoked; default is 166 ms. 166 corresponds to 10 frames at 60 Hz. - @returns The debounced function, with a
clearmethod to cancel any pending execution.
Example
const debouncedLog = debounce((msg: string) => console.log(msg), 200);
debouncedLog("Hello"); // Executes function after 200 ms
debouncedLog.clear(); // Cancels pending execution