Skip to content

Commit f3d71ea

Browse files
committed
debounce hook fixup
1 parent 6c6abf4 commit f3d71ea

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

client/src/Hooks/useDebouncedFunction.hook.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import { useEffect, useReducer } from 'react';
33

44
/**
55
* Хук Debounced Function
6-
* @param {void} callback
6+
* @param {(arg)=>void} callback
77
* @param {number} delayms
88
*/
99
function useDebouncedFunction(callback, delayms) {
10-
const [state, debounced] = useReducer(() => {
11-
return { count: state.count++, args: arguments }
12-
}, { count: 0, args: undefined })
10+
const [state, debounced] = useReducer((state, arg) => {
11+
return { count: state.count++, arg: arg }
12+
}, { count: 0, arg: undefined })
1313
useEffect(() => {
14-
const handler = setTimeout(() => callback(state.arguments), delayms)
14+
const handler = setTimeout(() => callback(state.arg), delayms)
1515
return () => clearTimeout(handler)
1616
// eslint-disable-next-line react-hooks/exhaustive-deps
1717
}, [state])

0 commit comments

Comments
 (0)