Skip to content

Latest commit

 

History

History
86 lines (72 loc) · 2.29 KB

use-pedometer.md

File metadata and controls

86 lines (72 loc) · 2.29 KB

usePedometer

Track user step count with Pedometer

releases builds demo

Other hooks   —   Usage   —   Changelog


expo install @use-expo/sensors expo-sensors

Usage

// full hook
const [data, isAvailable] = usePedometer();

// other options
usePedometer({ initial: { steps: 5 } });
usePedometer({ availability: false });

Example

function PedometerSensor() {
    const [data, available] = usePedometer();

    return (
        <View>
            <Text>Pedometer:</Text>
            {(available && data)
                ? <Text>{data.steps} steps</Text>
                : <Text>unavailable</Text>
            }
        </View>
    );
}

API

function usePedometer(options?: Options): Result;

interface Options {
    /** The initial data to use before the first update. */
    initial?: PedometerMeasurement;
    /** If it should check the availability of the sensor, defaults to `true`. */
    availability?: boolean;
}

type Result = [
    PedometerMeasurement | undefined,
    boolean | undefined,
];

interface PedometerMeasurement {
    /** The amount of steps made */
    steps: number;
}

with ❤️ byCedric