Created
November 21, 2019 06:54
-
-
Save devesh2605/bc4caa10b2a0e782a6ab76733ecfa24a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 from 'react'; | |
class OrientationDetection extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
orientation: 0 | |
} | |
} | |
componentDidMount() { | |
window.addEventListener('orientationchange', () => { | |
this.setState({ | |
orientation: window.orientation | |
}, () => { | |
console.log('orientation: ', this.state.orientation); | |
}) | |
}, false); | |
} | |
componentWillUnmount() { | |
window.removeEventListener('orientationchange', () => { | |
console.log('removed orientationchange'); | |
}, false); | |
} | |
render() { | |
return ( | |
<div> | |
{this.state.orientation === 90 ? <p>I am only Visible in Landscape</p> : null} | |
</div> | |
) | |
} | |
} | |
export default OrientationDetection; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment