use-debounce
Advanced tools
Changelog
7.0.0
useDebounce
hook changed isPending
behavior from async
reacting to the sync. Now isPending
returns True
as soon as the new value is sent to the hook.Changelog
6.0.0
breaking change: removed callback
field, instead of this useDebouncedCallback
and useThrottledCallback
returns a callable function:
Old:
const { callback, pending } = useDebouncedCallback(/*...*/);
// ...
debounced.callback();
New:
const debounced = useDebouncedCallback(/*...*/);
// ...
debounced();
/**
* Also debounced has fields:
* {
* cancel: () => void
* flush: () => void
* isPending: () => boolean
* }
* So you can call debounced.cancel(), debounced.flush(), debounced.isPending()
*/
It makes easier to understand which cancel \ flush or isPending is called in case you have several debounced functions in your component
breaking change: Now useDebounce
, useDebouncedCallback
and useThrottledCallback
has isPending
method instead of pending
Old:
const { callback, pending } = useDebouncedCallback(/*...*/);
New:
const { isPending } = useDebouncedCallback(/*...*/);
/**
* {
* cancel: () => void
* flush: () => void
* isPending: () => boolean
* }
*/
get rid of useCallback
calls
improve internal typing
decrease the amount of functions to initialize each useDebouncedCallback
call
reduce library size:
Whole library: from 946 B to 899 B === 47 B useDebounce: from 844 to 791 === 53 B useDebouncedCallback: from 680 to 623 === 57 B useThrottledCallback: from 736 to 680 === 56 B
Changelog
5.2.1
useDebounce
now. https://github.com/xnimorz/use-debounce/pull/95 Thanks to @csu-feizaoChangelog
5.1.0
— wait
param is optional. If you don't provide a wait argument, use-debounce will postpone a callback with requestAnimationFrame if it's in browser environment, or through setTimeout(..., 0) otherwise.