I am looking for a solution to call different functions as per orientation
if (window.innerHeight > window.innerWidth) {
alert("You are in portrait mode");
<Portrait />
}
if (window.innerHeight < window.innerWidth) {
alert("You are in landscape mode");
<Landscape />
}
Written the following functions
export default function Landscape() {
return (
<main>...</main>
);
}
function Portrait() {
return (
<main>...</main>
);
}
Problem
- Every time, only Landscape function getting called (I understand because I mentioned default)
- Atleast, I was expecting Portrait function to be called, when device in portrait mode
Please help to get it done
2
Answers
}
You can also use this custom hook.
It utilizes the new screen.orientation feature instead of checking innerHeight / innerWidth.
As of March 2023, it works across the latest devices and browser versions.