mirror of
https://github.com/yume-chan/ya-webadb.git
synced 2025-10-06 03:50:18 +02:00
18 lines
533 B
TypeScript
18 lines
533 B
TypeScript
import { useEffect, useState } from 'react';
|
|
|
|
export function useDevicePixelRatio() {
|
|
const [value, setValue] = useState(window.devicePixelRatio);
|
|
|
|
useEffect(() => {
|
|
const match = window.matchMedia(
|
|
`(min-device-pixel-ratio: ${value}) and (max-device-pixel-ratio: ${value})`
|
|
);
|
|
|
|
function handler() {
|
|
setValue(window.devicePixelRatio);
|
|
}
|
|
match.addEventListener('change', handler);
|
|
|
|
return match.removeEventListener('change', handler);
|
|
}, [value]);
|
|
}
|