Skip to content

Instantly share code, notes, and snippets.

@r3nya
Created February 1, 2016 22:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save r3nya/7ec4fa71d2194c48cb97 to your computer and use it in GitHub Desktop.
Save r3nya/7ec4fa71d2194c48cb97 to your computer and use it in GitHub Desktop.
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