Documentation Index
Fetch the complete documentation index at: https://mintlify.com/kingstinct/react-native-healthkit/llms.txt
Use this file to discover all available pages before exploring further.
Convenience functions to quickly retrieve the most recent sample of a specific data type.
getMostRecentQuantitySample
Get the most recent quantity sample for a specific identifier.
function getMostRecentQuantitySample(
identifier: QuantityTypeIdentifier,
unit?: string
): Promise<QuantitySample | undefined>
identifier
QuantityTypeIdentifier
required
The quantity type identifier
Optional unit for the quantity. If not specified, uses the user’s preferred unit.
Returns: Promise<QuantitySample | undefined> - The most recent sample, or undefined if no data exists
Example
import { getMostRecentQuantitySample } from '@kingstinct/react-native-healthkit';
// Get most recent step count
const steps = await getMostRecentQuantitySample(
'HKQuantityTypeIdentifierStepCount'
);
if (steps) {
console.log(`Steps: ${steps.quantity} ${steps.unit}`);
}
// Get heart rate in specific unit
const heartRate = await getMostRecentQuantitySample(
'HKQuantityTypeIdentifierHeartRate',
'count/min'
);
getMostRecentCategorySample
Get the most recent category sample for a specific identifier.
function getMostRecentCategorySample<T extends CategoryTypeIdentifier>(
identifier: T
): Promise<CategorySampleTyped<T> | undefined>
identifier
CategoryTypeIdentifier
required
The category type identifier
Returns: Promise<CategorySample | undefined> - The most recent sample, or undefined if no data exists
Example
import { getMostRecentCategorySample } from '@kingstinct/react-native-healthkit';
// Get most recent sleep session
const sleep = await getMostRecentCategorySample(
'HKCategoryTypeIdentifierSleepAnalysis'
);
if (sleep) {
console.log(`Sleep value: ${sleep.value}`);
console.log(`Duration: ${sleep.endDate - sleep.startDate}ms`);
}
// Get most recent mindful session
const mindful = await getMostRecentCategorySample(
'HKCategoryTypeIdentifierMindfulSession'
);
getMostRecentWorkout
Get the most recent workout sample.
function getMostRecentWorkout(): Promise<WorkoutSample | undefined>
Returns: Promise<WorkoutSample | undefined> - The most recent workout, or undefined if no workouts exist
Example
import { getMostRecentWorkout } from '@kingstinct/react-native-healthkit';
const workout = await getMostRecentWorkout();
if (workout) {
console.log(`Activity: ${workout.workoutActivityType}`);
console.log(`Duration: ${workout.duration} seconds`);
console.log(`Distance: ${workout.totalDistance?.quantity} ${workout.totalDistance?.unit}`);
console.log(`Energy: ${workout.totalEnergyBurned?.quantity} ${workout.totalEnergyBurned?.unit}`);
// Access workout methods
const routes = await workout.getWorkoutRoutes();
}
Use cases
These utilities are perfect for:
- Dashboard displays - Show current health metrics
- Quick checks - Verify if data exists before complex queries
- Status indicators - Display most recent values
- Initial data loading - Fetch latest value on app start
React Hooks alternative
For reactive data that auto-updates, use these hooks instead:
Notes
These functions are thin wrappers around query functions with limit: 1 and
descending sort order. Use the full query APIs for more control.
Always request authorization before calling these functions.