title: React Hooks + window.addEventListener in useEffect
body: <p>I'm trying to <code>console.log</code> the html element where the user is typing.</p>
  <p>To do that I've implemented the following hook:</p>
  <pre><code>export const useGetActiveElement = () =&gt; {
  
  const [activeElement, setActiveElement] = useState()
  
  useEffect(() =&gt; {
    if (window){
      window.addEventListener('keyup', setCorrectElement);
    }
    return () =&gt; {
      window.removeEventListener('keyup', setCorrectElement);
    }
  }, [])
  
  const setCorrectElement = (element) =&gt; {
    if(element.target.tagName === 'INPUT' || element.target.tagName === 'TEXTAREA') {
      setActiveElement(element.target)
    }
  }
  
  return activeElement}
  </code></pre>
  <pre><code>export default () =&gt; {
          const activeElement = useGetActiveElement()
  
          console.log(activeElement)  &lt;==== Here! Only prints the value 2 or 3 times... 
  
          return &lt;AnotherComponent /&gt;
  }
  </code></pre>
  <p>For some reason I don't understand, the value is printed a couple of times in the console, but at some point, it just doesn't print anymore.</p>
  <p>I'm not sure if this is a Ref issue... But couldn't find a reasonable explanation.</p>
  <p>Ideas?</p>
  <p>Thanks</p>