Guest User

Untitled

a guest
Dec 9th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. constructor(props) {
  2. super(props);
  3. this.state = { width: 0, height: 0 };
  4. this.updateWindowDimensions = this.updateWindowDimensions.bind(this);
  5. }
  6.  
  7. componentDidMount() {
  8. this.updateWindowDimensions();
  9. window.addEventListener('resize', this.updateWindowDimensions);
  10. }
  11.  
  12. componentWillUnmount() {
  13. window.removeEventListener('resize', this.updateWindowDimensions);
  14. }
  15.  
  16. updateWindowDimensions() {
  17. this.setState({ width: window.innerWidth, height: window.innerHeight });
  18. }
Add Comment
Please, Sign In to add comment