title: React useState doesn't update in window events
body: <p>State does get set on the scroll, but logged from the eventlistener, it seems to be stuck at the initial value.</p>
  
  <p>I guess it's something to do with <code>scrolling</code> being set when the side effect's defined, but how could I trigger a state change from a scroll otherwise? Same goes for any window event I presume.</p>
  
  <p>Here's a codesandbox example: <a href="https://codesandbox.io/s/react-test-zft3e" rel="noreferrer">https://codesandbox.io/s/react-test-zft3e</a> </p>
  
  <pre><code>  const [scrolling, setScrolling] = useState(false);
  
    useEffect(() =&gt; {
      window.addEventListener("scroll", () =&gt; {
        console.log(scrolling);
        if (scrolling === false) setScrolling(true);
      });
    }, []);
  
    return (
      &lt;&gt;
        scrolling: {scrolling}
      &lt;/&gt;
    );
  </code></pre>