-
-
Save itsmepetrov/ac5a309a7604447e5bbf to your computer and use it in GitHub Desktop.
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
import React, { PropTypes, Component, Children, cloneElement } from 'react'; | |
export default class Fullscreen extends Component { | |
static propTypes = { | |
children: PropTypes.node | |
}; | |
state = { | |
width: 0, | |
height: 0 | |
}; | |
componentDidMount() { | |
this.setState(this.getDimensions()); | |
window.addEventListener('resize', this.handleResize); | |
} | |
componentWillUnmount() { | |
window.removeEventListener('resize', this.handleResize); | |
} | |
getDimensions() { | |
return { | |
width: window.innerWidth, | |
height: window.innerHeight | |
}; | |
} | |
handleResize = () => { | |
this.setState(this.getDimensions()); | |
}; | |
render() { | |
const { children } = this.props; | |
const { width, height } = this.state; | |
const child = cloneElement(Children.only(children), { width: width, height: height}); | |
return child; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment