Skip to content

useDevicePixelRatio ​

Hook that returns the device's pixel ratio

utilities
test coverage
Last changed: last month

TIP

This hook uses window.devicePixelRatio browser api to provide enhanced functionality. Make sure to check for compatibility with different browsers when using this api

Installation ​

Library
CLI
Manual
typescript
import { useDevicePixelRatio } from '@siberiacancode/reactuse';

Usage ​

typescript
const { supported, ratio } = useDevicePixelRatio();

Demo ​

Api ​

Returns

UseDevicePixelRatioReturn

Type declaration ​

typescript
export interface UseDevicePixelRatioReturn {
  /** The ratio of the resolution in physical pixels to the resolution in CSS pixels */
  ratio: number;
  /** Whether the device pixel ratio is supported*/
  supported: boolean;
}

Source ​

Source • Demo

Contributors ​

D
debabin
debabin
A
Artem Dereviago
Artem Dereviago

Released under the MIT License.