use-debounce
Advanced tools
Comparing version 5.0.0 to 5.0.1
@@ -0,1 +1,5 @@ | ||
## 5.0.1 | ||
- Fix typing to infer correct callback type (thanks to [@lytc](https://github.com/lytc)) | ||
## 5.0.0 | ||
@@ -6,2 +10,3 @@ | ||
Old: | ||
```js | ||
@@ -12,2 +17,3 @@ const [debouncedCallback, cancelDebouncedCallback, callPending] = useDebouncedCallback(/*...*/); | ||
New: | ||
```js | ||
@@ -21,3 +27,3 @@ const debounced = useDebouncedCallback(/*...*/); | ||
* pending: () => boolean, which is a new function | ||
* } | ||
* } | ||
*/ | ||
@@ -28,2 +34,3 @@ ``` | ||
Old: | ||
```js | ||
@@ -34,2 +41,3 @@ const [value, cancel, callPending] = useDebounce(/*...*/); | ||
New: | ||
```js | ||
@@ -39,7 +47,7 @@ const [value, fn] = useDebouncedCallback(/*...*/); | ||
* value is just a value without changes | ||
* But fn now is an object: { | ||
* But fn now is an object: { | ||
* cancel: () => void, which is cancel | ||
* flush: () => void, which is callPending | ||
* pending: () => boolean, which is a new function | ||
* } | ||
* } | ||
*/ | ||
@@ -69,3 +77,2 @@ ``` | ||
## 4.0.0 | ||
@@ -81,3 +88,3 @@ | ||
maxWait: 300, | ||
}) | ||
}); | ||
``` | ||
@@ -84,0 +91,0 @@ |
@@ -11,5 +11,5 @@ export interface Options { | ||
} | ||
export interface DebouncedState<T extends unknown[]> extends ControlFunctions { | ||
callback: (...args: T) => unknown; | ||
export interface DebouncedState<T extends (...args: any[]) => ReturnType<T>> extends ControlFunctions { | ||
callback: (...args: Parameters<T>) => ReturnType<T>; | ||
} | ||
export default function useDebouncedCallback<T extends unknown[]>(func: (...args: T) => unknown, wait: number, options?: Options): DebouncedState<T>; | ||
export default function useDebouncedCallback<T extends (...args: any[]) => ReturnType<T>>(func: T, wait: number, options?: Options): DebouncedState<T>; |
@@ -11,5 +11,5 @@ export interface Options { | ||
} | ||
export interface DebouncedState<T extends unknown[]> extends ControlFunctions { | ||
callback: (...args: T) => unknown; | ||
export interface DebouncedState<T extends (...args: any[]) => ReturnType<T>> extends ControlFunctions { | ||
callback: (...args: Parameters<T>) => ReturnType<T>; | ||
} | ||
export default function useDebouncedCallback<T extends unknown[]>(func: (...args: T) => unknown, wait: number, options?: Options): DebouncedState<T>; | ||
export default function useDebouncedCallback<T extends (...args: any[]) => ReturnType<T>>(func: T, wait: number, options?: Options): DebouncedState<T>; |
{ | ||
"name": "use-debounce", | ||
"version": "5.0.0", | ||
"version": "5.0.1", | ||
"description": "Debounce hook for react", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -197,2 +197,20 @@ # useDebounce react hook | ||
#### Pending method | ||
`pending` method shows whether component has pending callbacks. Works for both `useDebounce` and `useDebouncedCallback`: | ||
```javascript | ||
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>; | ||
} | ||
``` | ||
#### leading calls | ||
@@ -199,0 +217,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36980
255