I'm trying to debounce an onChange event when a user type in a input field.
I'm referencing these threads:
Set input value with a debounced onChange handler
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?
 
     
     
    