File tree Expand file tree Collapse file tree 1 file changed +13
-11
lines changed
packages/hooks/src/useDebounceFn Expand file tree Collapse file tree 1 file changed +13
-11
lines changed Original file line number Diff line number Diff line change 1
- import debounce from " lodash/debounce" ;
1
+ import debounce from ' lodash/debounce'
2
2
3
3
export interface DebounceOptions {
4
- wait ?: number ;
5
- leading ?: boolean ;
6
- trailing ?: boolean ;
7
- maxWait ?: number ;
4
+ wait ?: number
5
+ leading ?: boolean
6
+ trailing ?: boolean
7
+ maxWait ?: number
8
8
}
9
9
10
- type noop = ( ...args : any ) => any ;
10
+ type noop = ( ...args : any ) => any
11
11
12
12
function useDebounceFn < T extends noop > ( fn : T , options ?: DebounceOptions ) {
13
- const wait = options ?. wait ?? 1000 ;
14
- const run = debounce ( fn , wait , options ) ;
13
+ const wait = options ?. wait ?? 1000
14
+ const debounced = debounce ( fn , wait , options )
15
15
return {
16
- run,
17
- } ;
16
+ run : debounced ,
17
+ cancel : debounced . cancel ,
18
+ flush : debounced . flush ,
19
+ }
18
20
}
19
21
20
- export default useDebounceFn ;
22
+ export default useDebounceFn
You can’t perform that action at this time.
0 commit comments