title: Facing an issue with debouncing In React
body: <p>In my project, I want to use debounce method but this code is not working properly. It prints the input value continuously after a delay. I just want to print the input value when the user's typing is over.</p>
  <pre><code>const [searchItem, setSearchItem] = useState('');
  
  const getData = () =&gt; console.log(searchItem);
  
  const handleSearch = (fn, delay) =&gt; {
      let timer;
      return () =&gt; {
          clearTimeout(timer);
  
          timer = setTimeout(() =&gt; {
              fn();
          }, delay)
      }
  }
  
  const search = handleSearch(getData, 1000)
  
  return (
      &lt;section className=&quot;container&quot;&gt;
          &lt;h2 className=&quot;main__title&quot;&gt;Search Name&lt;/h2&gt;
          &lt;input type=&quot;text&quot; onKeyUp={search} value={searchItem} onChange={e =&gt; setSearchItem(e.target.value.toLowerCase().trim())} placeholder=&quot;Seach Name&quot; className=&quot;search__input&quot; /&gt;
      &lt;/section&gt;
  );
  </code></pre>
  <p>I just want to print the name in the console when the user's typing is over or after 1s delay.</p>