title: react hooks useEffect update window.innerHeight
body: <p>I want to update state with the inner window height as I resize the screen. When I log the state height within the <code>useEffect</code> hook I get 0 each time however, when I log inside the <code>updateWindowDimensions</code> function the height value is updated as expected. </p>
  
  <p>How can I update state with the new value each time? </p>
  
  <pre><code>const [height, setHeight] = useState(0);
  
  const updateWindowDimensions = () =&gt; {
      const newHeight = window.innerHeight;
      setHeight(newHeight);
      console.log('updating height');   
  };
  
   useEffect(() =&gt; {
       window.addEventListener('resize', updateWindowDimensions);
       console.log("give height", height);
   }, []);
  </code></pre>