UNPKG

use-screen-details

Version:

React hook to get details of the screen

26 lines (25 loc) 736 B
import { useCallback as r, useState as a, useEffect as s } from "react"; function c() { const e = r(() => { const { orientation: n } = window.screen; return { type: (n == null ? void 0 : n.type) || "unknown", angle: (n == null ? void 0 : n.angle) || 0 }; }, []), [o, i] = a( () => typeof window < "u" ? e() : { type: "unknown", angle: 0 } ); return s(() => { var t; if (typeof window > "u" || !((t = window.screen) != null && t.orientation)) return; const n = () => { i(e()); }; return window.screen.orientation.addEventListener("change", n), () => { window.screen.orientation.removeEventListener("change", n); }; }, [e]), o; } export { c as useOrientation };