Skip to content

useDeviceMotion ​

utilities
test coverage
Last changed: 28 days ago

TIP

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

Hook that work with device motion

typescript
import { useDeviceMotion } from '@siberiacancode/reactuse';

Usage ​

typescript
const { interval, rotationRate, acceleration, accelerationIncludingGravity } = useDeviceMotion();

Demo ​

Api ​

Parameters

NameTypeDefaultNote
delay?number1000The delay in milliseconds
callback?(event: DeviceMotionEvent) => void-The callback function to be invoked
enabled?booleantrueWhether to enable the hook

Source ​

Source • Demo

Contributors ​

Avatardebabin
AvatarMichael Mironychev

Released under the MIT License.