Created
May 14, 2015 23:15
-
-
Save craigbeck/0a9b20b417ed5fe0b886 to your computer and use it in GitHub Desktop.
React ViewportInfo component
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
var ViewportInfo = React.createClass({ | |
getInitialState: function () { | |
return { | |
width: null, | |
height: null | |
}; | |
}, | |
componentDidMount: function () { | |
this.getWindowDimensions(); | |
window.addEventListener("resize", this.getWindowDimensions); | |
}, | |
componentWillUnmount: function () { | |
window.removeEventListener("resize", this.getWindowDimensions); | |
}, | |
getWindowDimensions: function () { | |
this.setState({ | |
width: window.innerWidth, | |
height: window.innerHeight | |
}); | |
}, | |
render: function () { | |
return ( | |
<div> | |
<span>{this.state.width}</span> × <span>{this.state.height}</span> | |
</div> | |
); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment