title: Invalid hook call when trying to fetch data using useCallback
body: <p>I'm trying to call <code>useState</code> inside an async function like:</p>
  
  <pre><code>const [searchParams, setSearchParams] = useState({});
  
  const fetchData = () =&gt; useCallback(
      () =&gt; {
        if (!isEmpty(searchParams)) {
          setIsLoading(true); // this is a state hook
          fetchData(searchParams)
            .then((ids) =&gt; {
              setIds(ids); // Setting the id state here
            }).catch(() =&gt; setIsLoading(false));
        }
      },
      [],
    );
  </code></pre>
  
  <p>There are two states I am trying to set inside this <code>fetchData</code> function (<code>setIsLoading</code> and <code>setIds</code>), but whenever this function is executed am getting the error:</p>
  
  <blockquote>
    <p>Uncaught Error: 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</p>
  </blockquote>
  
  <p>What is this Rule of hooks I am breaking here?
  Is there any way around to set these states from the function?</p>
  
  <p>PS: I only used the <code>useCallback</code> hook here for calling this function with <code>lodash/debounce</code></p>
  
  <p>Edit: The function is called inside <code>useEffect</code> like:</p>
  
  <pre><code>const debouncedSearch = debounce(fetchSearchData, 1000); // Is this the right way to use debounce? I think this is created every render.
  
  const handleFilter = (filterParams) =&gt; {
      setSearchParams(filterParams);
  };
  
  useEffect(() =&gt; {
      console.log('effect', searchParams); // {name: 'asd'}
      debouncedSearch(searchParams); // Tried without passing arguments here as it is available in state.
  // But new searchParams are not showing in the `fetchData`. so had to pass from here.
  }, [searchParams]);
  </code></pre>