title: React Server Side Rendering - addEventListener
body: <p>I have a server side rendering react app (because I need Facebook Seo as well).</p>
  
  <p>A part of my app requires to get window.innerWidth. </p>
  
  <p>I have been searching for a long time, most of them says you cannot find window on server side, so you need to do <strong>rendering on client side as well</strong>.</p>
  
  <p>I'm not sure how things work, I have componentdidmount but my windowWidth is forever 0.</p>
  
  <p>After server rendering, our bundle.js will kick in and window on client side will work right? How come it's still 0?</p>
  
  <pre><code>state = {
        windowWidth: 0
  }
      handleResize(){
          this.setState({windowWidth: window.innerWidth});
      }
  
      componentDidMount () {
          window.addEventListener('resize', this.handleResize);
       }
  
      componentWillUnmount () {
       window.removeEventListener('resize', this.handleResize);
  
      }
  
  render() {
  return (&lt;div&gt;{this.state.windowWidth}&lt;/div&gt;)
  }
  </code></pre>