Skip to content

Latest commit

 

History

History
36 lines (28 loc) · 742 Bytes

File metadata and controls

36 lines (28 loc) · 742 Bytes

useDeviceMotion

Vue hook that tracks state of device's motion sensor.

Browser environment is required

Usage

import { createComponent } from '@vue/composition-api'
import { useDeviceMotion } from 'vuses'

const Demo = createComponent({
  setup() {
    const motion = useDeviceMotion()
    return { motion }
  },
  render() {
    const { motion } = this
    return <pre>{JSON.stringify(motion, null, 2)}</pre>
  }
})

Reference

interface MotionState {
  acceleration: DeviceMotionEventAcceleration
  accelerationIncludingGravity: DeviceMotionEventAcceleration
  rotationRate: DeviceMotionEventRotationRate
  interval: number | null
}

function useDeviceMotion(initialState: MotionState): MotionState