Created
December 15, 2017 03:25
-
-
Save overthemike/1d9190096c9307d72cd8494ade61695b to your computer and use it in GitHub Desktop.
responsivereact.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for your analysis. It is new and different aspects I know before. Looking forward to reading more of your posts wingsio