import { useEffect , useState } from 'react' ; import { Pedometer } from 'expo-sensors' ; see https example export function usePedometer ( options = { } ) { const [ data , setData ] = useState ( options . initial ) ; const [ available , setAvailable ] = useState < boolean > ( ) ; const { availability = true } = options ; useEffect ( ( ) => { if ( availability ) { Pedometer . isAvailableAsync ( ) . then ( setAvailable ) ; } return Pedometer . watchStepCount ( setData ) . remove ; } , [ availability ] ) ; return [ data , available ] ; } export interface PedometerResult { /** The amount of steps made */ steps : number ; } export interface PedometerOptions { /** The initial data to use before the first update. */ initial ? : PedometerResult ; /** If it should check the availability of the sensor, defaults to `true`. */ availability ? : boolean ; }