Skip to main content

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

FeatureiOS (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:

  1. Consistent data types - Sleep sessions have the same structure on both platforms
  2. Automatic platform detection - No need for Platform.select() everywhere
  3. Graceful degradation - Handles platform limitations (e.g., iOS doesn't support sleep write)
  4. Simplified setup - One Expo plugin configures both platforms

Credits

This library is inspired by and builds upon: