title: screen orientation on react native
body: <p>I am trying to add the rotation functionality on react native using expo. Followed tutorials and searched on google and here but somehow none of them are working. The screen size is not getting detected when i rotate the simulator. Therefore it doesn't change from portrait to landscape or vice versa.
  You can see the code below that i tried through following a working example but its not working when i apply it. Any help is very much appreciated.</p>
  <pre><code>const [orientation, setOrientation] = useState(&quot;&quot;);
  const window = useWindowDimensions();
  
   useEffect(() =&gt; {
    Dimensions.addEventListener(&quot;change&quot;, ({ window: { width, height } }) =&gt; {
     if (width &lt; height) {
      // this is in portrait mode
      setOrientation(&quot;Portrait&quot;);
     } else {
      // this is in landscape mode
      setOrientation(&quot;Landscape&quot;);
     }
   });
  }, []);
  
  return (
    &lt;View style={styles.container}&gt;
     &lt;Text style={{ color: &quot;red&quot;, fontSize: 30, fontWeight: &quot;bold&quot; }}&gt;
       {orientation}
     &lt;/Text&gt;
    &lt;/View&gt;
  
  const styles = StyleSheet.create({
    container: {
    flex: 1,
    alignItems: &quot;center&quot;,
    justifyContent: &quot;center&quot;,
   },
  });
  </code></pre>