title: Infinite loop React hooks
body: <p>I don't understand why I'm getting infinite loop in 
  <strong>useClick</strong> I see that I change state value inside <strong>useEffect</strong> using <strong>setVal</strong> but useEffect should work only on onClick as specified in second param. I thought that it is because the param onClick i pass is memoized but the callback is not called(i checked that using <strong>console.log('go set')</strong></p>
  
  <pre><code>function useClick(onClick, setVal, val) {
    React.useEffect(() =&gt; {
      console.log('Click');
      setVal(val + 1);
    }, [onClick]);
  }
  
  const Home = () =&gt; {
    const [val, setVal] = React.useState(0);
    const incrementOnClick = React.useCallback(() =&gt; {
      console.log('go set');
      setVal(val + 1);
    } , [setVal, val]);
    useClick(incrementOnClick, setVal, val);
    return &lt;div&gt;
      &lt;div&gt;{val}&lt;/div&gt;
      &lt;button onClick={incrementOnClick}&gt;Click me&lt;/button&gt;
   &lt;/div&gt;
  }
  </code></pre>