Skip to content

Instantly share code, notes, and snippets.

@itsmepetrov
Forked from r3nya/fullscreen.js
Last active February 1, 2016 22:35
Show Gist options
  • Save itsmepetrov/ac5a309a7604447e5bbf to your computer and use it in GitHub Desktop.
Save itsmepetrov/ac5a309a7604447e5bbf to your computer and use it in GitHub Desktop.
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