Created
February 22, 2017 21:31
-
-
Save nma/33f8057e4899bdb55440a693a02c431b to your computer and use it in GitHub Desktop.
ReactJS get window sizes
This file contains hidden or 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
constructor(props) { | |
super(props); | |
this.state = { height: 512 }; | |
this.updateWindowDimensions = this.updateWindowDimensions.bind(this); | |
} | |
componentDidMount() { | |
this.updateWindowDimensions(); | |
window.addEventListener("resize", this.updateWindowDimensions.bind(this)); | |
} | |
componentWillUnmount() { | |
window.removeEventListener("resize", this.updateWindowDimensions.bind(this)); | |
} | |
updateWindowDimensions() { | |
this.setState({ width: window.innerWidth, height: window.innerHeight }); | |
} |
Thank You
Thank you) works very well!) 👍
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works like a charm. Thanks!