Releases: xnimorz/use-debounce
8.0.2
- Added type exports. #136 Thanks to @tryggvigy
- Improved code comments. #135 Thanks to @tryggvigy
8.0.1
8.0.0
- breaking change
useDebounce
changed its build system to microbundle. For now we have several entries:
index.js
is for commonJS approach
index.modern.js
for esnext module system
index.umd.js
for UMD.
All the files are in dist
folder.
If you have any paths which have esm
or lib
, please, replace them to dist
:
Before:
import useDebounceCallback from 'use-debounce/lib/useDebounceCallback'
After:
import { useDebounceCallback } from 'use-debounce';
- Fixed issue with incorrect VSCode autocomplete #131 Thanks to @c-ehrlich for reporting
- Fixed
useDebounce
behaviour with react-devtools tab when devtools have a component withuseDebounce
oruseDebounceCallback
opened. #129 Thanks to @alexniarchos for reporting - Fixed issue with
leading: true
#124 Thanks to @mntnoe for reporting
7.0.0 isPending is sync
-
breakng change
useDebounce
hook changedisPending
behavior fromasync
reacting to the sync. NowisPending
returnsTrue
as soon as the new value is sent to the hook:
Example is here: https://github.com/xnimorz/use-debounce/blob/master/test/useDebounce.test.tsx#L303-L329 -
Dev dependencies updated
6.0.1
Clarifying API and major under hood improvements
-
breakind change: removed
callback
field, instead of thisuseDebouncedCallback
anduseThrottledCallback
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
anduseThrottledCallback
hasisPending
method instead ofpending
Old:
const { callback, pending } = useDebouncedCallback(/*...*/);
New:
const { callback, isPending } = useDebouncedCallback(/*...*/); /** * { * callback: (...args: any[]) => ReturnType<T> * 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
Unmounted components fix
- prevent having ininite setTimeout setup when component gets unmounted #97
- function type works correctly with
useDebounce
now. #95 Thanks to @csu-feizao
useThrottledCallback
- Added
useThrottledCallback
5.0.1
5.0.0
-
breaking change: Now
useDebouncedCallback
returns an object instead of array:Old:
const [debouncedCallback, cancelDebouncedCallback, callPending] = useDebouncedCallback(/*...*/);
New:
const debounced = useDebouncedCallback(/*...*/); /** * debounced: { * callback: (...args: T) => unknown, which is debouncedCallback * cancel: () => void, which is cancelDebouncedCallback * flush: () => void, which is callPending * pending: () => boolean, which is a new function * } */
-
breaking change: Now
useDebounce
returns an array of 2 fields instead of a plain array:
Old:const [value, cancel, callPending] = useDebounce(/*...*/);
New:
const [value, fn] = useDebouncedCallback(/*...*/); /** * value is just a value without changes * But fn now is an object: { * cancel: () => void, which is cancel * flush: () => void, which is callPending * pending: () => boolean, which is a new function * } */
-
Added
pending
function to bothuseDebounce
anduseDebouncedCallback
which shows whether component has pending callbacks
Example:function Component({ text }) { const debounced = useDebouncedCallback(useCallback(() => {}, []), 500); expect(debounced.pending()).toBeFalsy(); debounced.callback(); expect(debounced.pending()).toBeTruthy(); debounced.flush(); expect(debounced.pending()).toBeFalsy(); return <span>{text}</span>; }
For more details of these major changes you could check this commit 1b4ac04 and this issue #61
- Fixed security alerts