Skip to content

Instantly share code, notes, and snippets.

@overthemike
Created December 15, 2017 03:25
Show Gist options
  • Save overthemike/1d9190096c9307d72cd8494ade61695b to your computer and use it in GitHub Desktop.
Save overthemike/1d9190096c9307d72cd8494ade61695b to your computer and use it in GitHub Desktop.
responsivereact.js
import React, {Component} from 'react'
import ReactDOM from 'react-dom'
import App from './components/App'
import Mobile from './components/Mobile'
class Main extends Component {
state = {
width: window.innerWidth
}
componentDidMount() {
window.addEventListener('resize', this.handleWindowResize)
}
componentWillUnmount() {
window.removeEventListener('resize', this.handleWindowResize)
}
handleWindowResize = (e) => {
this.setState({
width: window.innerWidth
})
}
render() {
if (this.state.width <= 1024) {
return <Mobile />
} else {
return <App />
}
}
}
ReactDOM.render(<Main />, document.getElementById('root'));
@windowsok
Copy link

Thank you for your analysis. It is new and different aspects I know before. Looking forward to reading more of your posts wingsio

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment