Template
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
23 lines
665 B
TypeScript
23 lines
665 B
TypeScript
import { useEffect, useState } from "react";
|
|
|
|
function getIsPortrait() {
|
|
if (typeof window === "undefined") return false;
|
|
return window.innerHeight > window.innerWidth;
|
|
}
|
|
|
|
export function useOrientation() {
|
|
const [isPortrait, setIsPortrait] = useState(getIsPortrait);
|
|
|
|
useEffect(() => {
|
|
const updateOrientation = () => setIsPortrait(getIsPortrait());
|
|
window.addEventListener("resize", updateOrientation);
|
|
window.addEventListener("orientationchange", updateOrientation);
|
|
return () => {
|
|
window.removeEventListener("resize", updateOrientation);
|
|
window.removeEventListener("orientationchange", updateOrientation);
|
|
};
|
|
}, []);
|
|
|
|
return isPortrait;
|
|
}
|