title: React search using debounce
body: <p>I am trying to implement a search that makes a new query on each character change. After n milliseconds, I need to make a change to the object that stores some properties.</p>
  <pre><code>//user typing
  const onInputChange = (e) =&gt; {
      let searchInput = e.target.value;
  
      useDebounce(
          handleSearchPropsChange({
              filter: {
                  searchInput,
                  dateRange: {
                      start,
                      end
                  }
              }
          }), 1000
      );
  }
  </code></pre>
  <p>The function I am using for the delayed call</p>
  <pre><code>import {debounce} from 'lodash';
  import {useRef} from 'react';
  
  export function useDebounce(callback = () =&gt; {}, time = 500) {
      return useRef(debounce(callback, time)).current;
  }
  </code></pre>
  <p>But I am getting the error:</p>
  <pre><code>Invalid hook call. Hooks can only be called inside of the body of a function component. This 
  could happen for one of the following reasons:
  1. You might have mismatching versions of React and the renderer (such as React DOM)
  2. You might be breaking the Rules of Hooks
  3. You might have more than one copy of React in the same app
  </code></pre>