useDeviceMotion ​
Hook that work with device motion
utilities
test coverage
Last changed: last month
TIP
This hook uses DeviceMotionEvent 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 { useDeviceMotion } from '@siberiacancode/reactuse';
Usage ​
typescript
const { interval, rotationRate, acceleration, accelerationIncludingGravity } = useDeviceMotion();
Demo ​
Api ​
Parameters
Name | Type | Default | Note |
---|---|---|---|
delay? | number | 1000 | The delay in milliseconds |
callback? | (event: DeviceMotionEvent) => void | - | The callback function to be invoked |
enabled? | boolean | true | Whether to enable the hook |
Returns
UseDeviceMotionReturn
Type declaration ​
typescript
export interface UseDeviceMotionReturn {
acceleration: DeviceMotionEventAcceleration;
accelerationIncludingGravity: DeviceMotionEventAcceleration;
interval: DeviceMotionEvent['interval'];
rotationRate: DeviceMotionEventRotationRate;
}
export interface UseDeviceMotionParams {
/** The delay in milliseconds */
delay?: number;
/** Whether to enable the hook */
enabled?: boolean;
/** The callback function to be invoked */
callback?: (event: DeviceMotionEvent) => void;
}
Source ​
Source • DemoContributors ​
D
M