Skip to content

Instantly share code, notes, and snippets.

@TiagoGouvea
Created June 12, 2017 12:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TiagoGouvea/2e08c8a24f91448f3557ffeb6a1333b1 to your computer and use it in GitHub Desktop.
Save TiagoGouvea/2e08c8a24f91448f3557ffeb6a1333b1 to your computer and use it in GitHub Desktop.
Responvie detect in window.resize
componentDidMount() {
window.addEventListener("resize", ()=> {
this.updateDimensions();
});
this.updateDimensions();
}
updateDimensions() {
let w = window,
d = document,
documentElement = d.documentElement,
body = d.getElementsByTagName('body')[0],
width = w.innerWidth || documentElement.clientWidth || body.clientWidth,
height = w.innerHeight || documentElement.clientHeight || body.clientHeight,
mobile = width < 740;
let appBarText = "Titulo muito longo para desktop";
if (mobile)
appBarText = "Titulo Curto";
console.log(width + ' x ' + height+': '+mobile);
this.setState({windowWidth: width, windowHeight: height, mobile: mobile, appBarText: appBarText});
if (mobile && this.state.menuOpen)
this.toggleMenu();
}
componentWillUnmount() {
window.removeEventListener("resize", this.updateDimensions);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment