Skip to content

Instantly share code, notes, and snippets.

@craigbeck
Created May 14, 2015 23:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save craigbeck/0a9b20b417ed5fe0b886 to your computer and use it in GitHub Desktop.
Save craigbeck/0a9b20b417ed5fe0b886 to your computer and use it in GitHub Desktop.
React ViewportInfo component
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> &times; <span>{this.state.height}</span>
</div>
);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment