Skip to content

useFunctionDebouncer react hook which exports a debounce(func, delay) function and a cancelDebounce function for debouncing in react apps

License

Notifications You must be signed in to change notification settings

aej11a/use-function-debouncer

Repository files navigation

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()

About

useFunctionDebouncer react hook which exports a debounce(func, delay) function and a cancelDebounce function for debouncing in react apps

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •