Created
May 22, 2019 09:15
-
-
Save roeib/7ff034c3b207fd87b64ad139c75fe7fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from "react"; | |
class MyComponent extends UseEffectExample { | |
constructor(props) { | |
super(props); | |
this.state = { | |
width: window.innerWidth; | |
}; | |
} | |
componentDidMount() { | |
window.addEventListener("resize", this.handleResize); | |
} | |
componentWillUnmount() { | |
window.removeEventListener("resize", this.handleResize); | |
} | |
handleResize = () =>{ | |
this.setState({ width: window.innerWidth }); | |
} | |
render() { | |
return ( | |
<h1>{this.state.width}</h1> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment