Introduction
react-native-healthx is a unified cross-platform health data API for React Native that provides access to iOS HealthKit and Android Health Connect through a single, consistent API.
Features
- Unified API: Single API for both iOS and Android
- TypeScript First: Full TypeScript support with comprehensive types
- Sleep Data: Read sleep sessions, stages, and aggregated statistics
- Promise-based: Modern async/await API
- Platform-aware: Gracefully handles platform differences
- Expo Support: Config plugin for automatic native configuration
Platform Support
| Feature | iOS (HealthKit) | Android (Health Connect) |
|---|---|---|
| Read Sleep | ✅ Yes | ✅ Yes |
| Write Sleep | ❌ No | ✅ Yes |
| Sleep Stages | ✅ Yes (iOS 16+) | ✅ Yes |
| Aggregation | ✅ Yes (JS) | ✅ Yes (Native) |
Quick Example
import HealthX from 'react-native-healthx';
// Initialize
await HealthX.initialize();
// Request permissions
await HealthX.requestPermissions({
sleep: { read: true, write: true }
});
// Get sleep sessions
const sessions = await HealthX.sleep.getSessions({
startDate: '2024-01-01T00:00:00Z',
endDate: '2024-01-31T23:59:59Z',
});
console.log(`Found ${sessions.length} sleep sessions`);
Why react-native-healthx?
Before react-native-healthx, accessing health data in React Native required using two separate libraries:
- react-native-health for iOS HealthKit
- react-native-health-connect for Android Health Connect
This library unifies both platforms into a single API, providing:
- Consistent data types - Sleep sessions have the same structure on both platforms
- Automatic platform detection - No need for Platform.select() everywhere
- Graceful degradation - Handles platform limitations (e.g., iOS doesn't support sleep write)
- Simplified setup - One Expo plugin configures both platforms
Credits
This library is inspired by and builds upon:
- react-native-health (iOS)
- react-native-health-connect (Android)