Skip to content

Instantly share code, notes, and snippets.

@rakibulalam
Last active April 18, 2017 18:58
Show Gist options
  • Save rakibulalam/e8cf9e213f5f27f0f12b4ea4377c48e8 to your computer and use it in GitHub Desktop.
Save rakibulalam/e8cf9e213f5f27f0f12b4ea4377c48e8 to your computer and use it in GitHub Desktop.
React Window height width
export default class home extends React.Component{
constructor(props) {
super(props);
this.state = { width: '0', height: '0' };
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 });
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment