Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.