Install dependency
yarn install @kingstinct/react-native-healthkit
Add Config Plugin to your app.json/app.config.js
{ "expo": { "plugins": [ "@kingstinct/react-native-healthkit" ] } }
// --- 2. Authorize 🔒 ---
import {
Text,
Button,
View
} from 'react-native';
import {
HKQuantityTypeIdentifier,
useHealthkitAuthorization
} from '@kingstinct/react-native-healthkit';
export default () => {
const [
authorizationStatus,
requestAuthorization
] = useHealthkitAuthorization([
HKQuantityTypeIdentifier.bloodGlucose
])
return <View>
<Text>Authorization Status: {authorizationStatus}</Text>
<Button
onPress={requestAuthorization}
title="Request Authorization"
/>
</View>
}
// --- 3. Launch 🚀 ---
import {
Text,
View
} from 'react-native';
import {
useMostRecentQuantitySample,
HKQuantityTypeIdentifier,
} from '@kingstinct/react-native-healthkit';
export default () => {
const sample = useMostRecentQuantitySample(
HKQuantityTypeIdentifier.bloodGlucose
)
return <View>
<Text>Blood Glucose: {sample?.quantity}</Text>
</View>
}