Skip to content

Latest commit

 

History

History
25 lines (15 loc) · 675 Bytes

README.md

File metadata and controls

25 lines (15 loc) · 675 Bytes

useFunctionDebouncer

useFunctionDebouncer is a React hook which can debounce (or delay) a function and provide a method to cancel the function.


What is debouncing?

Debouncing means delaying a function call.

 

How do I use it?

Use it like this:
const [debounce, cancelDebounce] = useFunctionDebouncer()

Pass a function to debounce and a time delay (in ms) to debounce it by like this:
debounce(() => console.log("Debounce me!"), 1000)

That will run console.log(...) after 1 second (1000 ms)

 

What else can I do?

If you'd like to cancel the function's execution during the debounce, run cancelDebounce()