Track changes in air pressure with Barometer
Other hooks — Usage — Changelog
expo install @use-expo/sensors expo-sensors
// full hook
const [data, isAvailable] = useBarometer();
// other options
useBarometer({ interval: 1000 });
useBarometer({ availability: false });
useBarometer({ initial: { pressure: 0 } });
import { useBarometer } from '@use-expo/sensors';
import { Text, View } from 'react-native';
function BarometerSensor() {
const [data, available] = useBarometer({ initial: { pressure: 0 } });
return (
<View>
<Text>Barometer:</Text>
{available
? <Text>{data.pressure * 100} Pa</Text>
: <Text>unavailable</Text>
}
</View>
);
}
import { BarometerMeasurement } from 'expo-sensors';
function useBarometer(options?: Options): Result;
interface Options {
/** The initial data to use before the first update. */
initial?: BarometerMeasurement;
/** If it should check the availability of the sensor, defaults to `true`. */
availability?: boolean;
/**
* The interval, in ms, to update the barometer data.
* Note, this is set globally through `Barometer.setUpdateInterval`.
* When used in 2 or more components, only the last rendered component's interval will be used for all.
*/
interval?: number;
}
type Result = [
BarometerMeasurement | undefined,
boolean | undefined,
];
with ❤️ byCedric