title: Debounce in React component JS
body: <p>I'm writing a simple debounce function for an input component</p>
  
  <pre><code>export const debounce = (func, wait) =&gt; {
      let timeout
      return function (...args) {
          if (timeout) {
              clearTimeout(timeout)
          }
          timeout = setTimeout(() =&gt; {
              timeout = null
              Reflect.apply(func, this, args)
          }, wait)
      }
  }
  </code></pre>
  
  <p>it imported from an external file, and used as a wrap for <code>input</code> onKeyUp handler inside a React component (Hooks)</p>
  
  <pre><code>const handleChange = debounce(() =&gt; console.log("test"), 1000)
  </code></pre>
  
  <p>PROBLEM: I'm getting "test" log every time when text in <code>input</code> changes, not only one - as expected.</p>
  
  <p>What am I doing wrong?</p>