I'm trying to debounce an onChange
event when a user type in a input field.
I'm referencing these threads:
I have the following snippet where I try to replicate the solutions provided in the threads above:
const handler = useCallback(debounce(setSearchQuery(value), 500), []);
useEffect(() => {
document.addEventListener('keydown', handleDocumentKeyDown);
handler(value);
return () => document.removeEventListener('keydown', handleDocumentKeyDown);
}, [isOpen, handleDocumentKeyDown, handler, value]);
// ...
const handleChange = (event) => {
setValue(event.target.value);
};
Error:
Uncaught TypeError: handler is not a function
How can I debounce setSerachQuery()
for 500ms
while the user is typing in the input field?
React Hook useCallback received a function whose dependencies are unknown. Pass an inline function instead.eslintreact-hooks/exhaustive-deps
– Depilate