Created
February 1, 2016 22:24
-
-
Save r3nya/7ec4fa71d2194c48cb97 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, cloneElement, Children } from 'react'; | |
const window = window; | |
export default class Fullscreen extends Component { | |
constructor(props) { | |
super(props); | |
this.state = this.getDimensions(); | |
} | |
static propTypes = { | |
children: PropTypes.node | |
}; | |
componentDidMount() { | |
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