When calling just the debounce function like this:
const handler = debounce(someFunction, 2000);
It will call the someFunction
on every keystroke. But when we wrap it in useCallback, it works fine.
const handler = useCallback(debounce(someFunction, 2000), []);
But as far as I know debounce function should call the someFunction
after 2000 ms and so the function should not be called on every keystroke. But it is not what I expected.
Can anyone explain why useCallback needed when using debounce?