Facing while experimenting with device orientation
Here is the code, I am using
import React, { useState, useEffect } from 'react';
export default function App() {
const [isLandscape, setIsLandscape] = useState(window.innerWidth > window.innerHeight);
useEffect(() => {
function handleResize() {
setIsLandscape(window.innerWidth > window.innerHeight);
}
window.addEventListener('resize', handleResize);
return () => window.removeEventListener('resize', handleResize);
}, []);
return (
<div>
{isLandscape ? <Landscape /> : <Portrait />}
</div>
);
}
And for your reference, here is the last and related question, I posted on SO
Calling functions as per device orientation
New contributor
ndisn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.