import { useEffect , useState } from 'react' ; import { Gyroscope , ThreeAxisMeasurement } from 'expo-sensors' ; see https remarks example export function useGyroscope ( options = { } ) { const [ data , setData ] = useState ( options . initial ) ; const [ available , setAvailable ] = useState < boolean > ( ) ; const { availability = true , interval , } = options ; useEffect ( ( ) => { if ( availability ) { Gyroscope . isAvailableAsync ( ) . then ( setAvailable ) ; } if ( interval !== undefined ) { Gyroscope . setUpdateInterval ( interval ) ; } return Gyroscope . addListener ( setData ) . remove ; } , [ availability , interval ] ) ; return [ data , available ] ; } export interface GyroscopeOptions { /** The initial data to use before the first update. */ initial ? : ThreeAxisMeasurement ; /** If it should check the availability of the sensor, defaults to `true`. */ availability ? : boolean ; /**
     * The interval, in ms, to update the gyroscope data.
     * Note, this is set globally through `Gyroscope.setUpdateInterval`.
     * When used in 2 or more components, only the last rendered component's interval will be used for all.
     */ interval ? : number ; }