Last active
April 18, 2017 18:58
-
-
Save rakibulalam/e8cf9e213f5f27f0f12b4ea4377c48e8 to your computer and use it in GitHub Desktop.
React Window height width
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
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