Skip to content

useDevicePixelRatio

Hook that returns the device's pixel ratio

utilities
low
test coverage
Last changed: 20 days 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, value } = useDevicePixelRatio();

Demo

Api

Parameters

NameTypeDefaultNote
callback?(value: number) => void-The callback to execute when the device pixel ratio changes

Returns

UseDevicePixelRatioReturn

Type declaration

typescript
export type UseDevicePixelRatioCallback = (value: number) => void;

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

Source

SourceDemo

Contributors

D
debabin
debabin
A
Artem Dereviago
Artem Dereviago

Released under the MIT License.