UNPKG

use-screen-details

Version:

React hook to get details of the screen

19 lines (18 loc) 497 B
import { useState as o, useEffect as d } from "react"; function a() { const [t, n] = o( () => typeof window < "u" ? window.devicePixelRatio : 1 ); return d(() => { if (typeof window > "u") return; const e = () => n(window.devicePixelRatio), i = window.matchMedia( `(resolution: ${window.devicePixelRatio}dppx)` ); return i.addEventListener("change", e), () => { i.removeEventListener("change", e); }; }, []), t; } export { a as useDevicePixelRatio };