Skip to content

useDevicePixelRatio

Hook that returns the device's pixel ratio

utilities
low
test coverage
Last changed: 8 months ago

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

SourceDemo

Contributors

D
debabin
debabin
A
Artem Dereviago
Artem Dereviago

Released under the MIT License.