npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@kingstinct/react-native-healthkit

v13.0.2

Published

React Native bindings for HealthKit

Readme

@kingstinct/react-native-healthkit

Test Status Latest version on NPM Downloads on NPM Discord

React Native bindings for HealthKit with full TypeScript and Promise support covering about any kind of data. Keeping TypeScript mappings as close as possible to HealthKit - both in regards to naming and serialization. This will make it easier to keep this library up-to-date with HealthKit as well as browsing the official documentation (and if something - metadata properties for example - is not typed it will still be accessible).

| Data Types | Query | Save | Subscribe | Examples | | ----------------------------|:------|:------|:----------|:---------------------------------------| | 100+ Quantity Types | ✅ | ✅ | ✅ | Steps, energy burnt, blood glucose etc.. | | 63 Category Types | ✅ | ✅ | ✅ | Sleep analysis, mindful sessions etc.. | | 75+ Workout Activity Types | ✅ | ✅ | ✅ | Swimming, running, table tennis etc.. | | Correlation Types | ✅ | ✅ | ✅ | Food and blood pressure | | Document Types | ✅ | ❌ | ✅ | CDA documents exposed as Base64 data | | Clinical Records | ⚠️ | ❌ | ⚠️ | Lab results etc in FHIR JSON format (see Clinical Records) |

Disclaimer

This library is provided as-is without any warranty and is not affiliated with Apple in any way. The data might be incomplete or inaccurate.

Installation

Expo

Usage with Expo is possible - just keep in mind it will not work in Expo Go and you'll need to roll your own Dev Client.

  1. yarn add @kingstinct/react-native-healthkit react-native-nitro-modules
  2. Update your app.json with the config plugin:
{
  "expo": {
    "plugins": ["@kingstinct/react-native-healthkit"]
  }
}

this will give you defaults that make the app build without any further configuration. If you want, you can override the defaults:

{
  "expo": {
    "plugins": [
      ["@kingstinct/react-native-healthkit", {
        "NSHealthShareUsageDescription": "Your own custom usage description",
        "NSHealthUpdateUsageDescription": "Your own custom usage description",
        "background": true
      }]
    ]
  }
}
  1. Build a new Dev Client

Native or Expo Bare Workflow

  1. yarn add @kingstinct/react-native-healthkit react-native-nitro-modules
  2. npx pod-install
  3. Set NSHealthUpdateUsageDescription and NSHealthShareUsageDescription in your Info.plist
  4. Enable the HealthKit capability for the project in Xcode.
  5. Since this package is using Swift you might also need to add a bridging header in your project if you haven't already, you can find more about that in the official React Native docs

Usage

During runtime check and request permissions with requestAuthorization. Failing to request authorization, or requesting a permission you haven't requested yet, will result in the app crashing. This is easy to miss - for example by requesting authorization in the same component where you have a hook trying to fetch data right away.. :)

Some hook examples:

import { useHealthkitAuthorization, saveQuantitySample } from '@kingstinct/react-native-healthkit';

const [authorizationStatus, requestAuthorization] = useHealthkitAuthorization(['HKQuantityTypeIdentifierBloodGlucose'])

// make sure that you've requested authorization before requesting data, otherwise your app will crash
import { useMostRecentQuantitySample, HKQuantityTypeIdentifier, useMostRecentCategorySample } from '@kingstinct/react-native-healthkit';

const mostRecentBloodGlucoseSample = useMostRecentQuantitySample('HKQuantityTypeIdentifierBloodGlucose')
const lastBodyFatSample = useMostRecentQuantitySample('HKQuantityTypeIdentifierBodyFatPercentage')
const lastMindfulSession = useMostRecentCategorySample('HKCategoryTypeIdentifierMindfulSession')
const lastWorkout = useMostRecentWorkout()

Some imperative examples:

  import { isHealthDataAvailable, requestAuthorization, subscribeToChanges, saveQuantitySample, getMostRecentQuantitySample } from '@kingstinct/react-native-healthkit';

  const isAvailable = await isHealthDataAvailable();

  /* Read latest sample of any data */
  await requestAuthorization({ toRead: ['HKQuantityTypeIdentifierBodyFatPercentage'] }); // request read permission for bodyFatPercentage

  const { quantity, unit, startDate, endDate } = await getMostRecentQuantitySample('HKQuantityTypeIdentifierBodyFatPercentage'); // read latest sample
  
  console.log(quantity) // 17.5
  console.log(unit) // %

  await requestAuthorization({
    toRead: ['HKQuantityTypeIdentifierHeartRate']
  }); // request read permission for heart rate

  /* Subscribe to data (Make sure to request permissions before subscribing to changes) */
  const [hasRequestedAuthorization, setHasRequestedAuthorization] = useState(false);
  
  useEffect(() => {
    requestAuthorization(['HKQuantityTypeIdentifierHeartRate']).then(() => {
      setHasRequestedAuthorization(true);
    });
  }, []);
  
  useEffect(() => {
    if (hasRequestedAuthorization) {
      const unsubscribe = subscribeToChanges('HKQuantityTypeIdentifierHeartRate', () => {
        // refetch data as needed
      });

      return () => unsubscribe();
    }
  }, [hasRequestedAuthorization]);

  /* write data */
  await requestAuthorization({ toShare: ['HKQuantityTypeIdentifierInsulinDelivery'] }); // request write permission for insulin delivery

  saveQuantitySample(
      'HKQuantityTypeIdentifierInsulinDelivery',
      'IU',
      5.5,
      {
        metadata: {
          // Metadata keys could be arbirtary string to store app-specific data.
          // To use built-in types from https://developer.apple.com/documentation/healthkit/samples/metadata_keys
          // you need to specify string values instead of variable names (by dropping MetadataKey from the name).
          HKInsulinDeliveryReason: HKInsulinDeliveryReason.basal,
        },
      }
    );

HealthKit Anchors

In 6.0 you can use HealthKit anchors to get changes and deleted items which is very useful for syncing. This is a breaking change - but a very easy one to handle that TypeScript should help you with. Most queries now return an object containing samples which is what was returned as only an array before.

newAnchor is a base64-encoded string returned from HealthKit that contain sync information. After each successful sync, store the anchor for the next time your anchor query is called to only return the values that have changed.

limit will indicate how many records to consider when sycning data, you can set this value to 0 indicate no limit.

Example:

  const { newAnchor, samples, deletedSamples } = await queryQuantitySamplesWithAnchor('HKQuantityTypeIdentifierStepCount', {
    limit: 2,
  })

  const nextResult = await queryQuantitySamplesWithAnchor('HKQuantityTypeIdentifierStepCount', {
    limit: 2,
    anchor: newAnchor,
  })

  // etc..

Migration to 9.0.0

There are a lot of under-the-hood changes in version 9.0.0, some of them are breaking (although I've tried to reduce it as much as possible).

  • The library has been migrated to react-native-nitro-modules. This improves performance, type-safety and gets rid of a lot of boilerplate code that made it harder to maintain and add features to the library.
  • Naming conventions have changed - most of the HK-prefixed stuff has been removed to avoid conflicts on the native side and also make the library more beautiful to look at. As an example the type previously called HKQuantityTypeIdentifier is now just QuantityTypeIdentifier.
  • Fewer required params - for example calling queryQuantitySamples('HKQuantityTypeIdentifierStepCount') without arguments will simply return the last 20 samples.
  • Flexible filters that map closer to the native constructs. For example this supports filtering by uuid, multiple uuids as well as on items related to a specific workout.
  • deleteObjects replaces all previous deletion methods, using the new flexible filters.
  • Workouts are returned as proxies containing not only data but also functions, for example getWorkoutRoutes.
  • Object identifiers are now just strings (not enums), but more strictly typed for each use case.
  • Units are now just strings. There's a isQuantityCompatibleWithUnit() helper function. Also, units are never required when querying, it always defaults to the users preferred unit.

A note on Apple Documentation

We're striving to do as straight a mapping as possible to the Native Libraries. This means that in most cases the Apple Documentation makes sense. However, when it comes to the Healthkit Metadata Keys the documentation doesn't actually reflect the serialized values. For example HKMetadataKeyExternalUUID in the documentation serializes to HKExternalUUID - which is what we use.

Clinical Records

For accessing Clinical Records use old version (3.x) or use specific branch "including-clinical-records". The reason is we cannot refer to this code natively in apps without getting approval from Apple, this could probably be solved by the config plugin but we haven't had time to look into it yet.

Android alternatives

For a similar library for Android, check out react-native-health-connect that works with the new Health Connect. For Google Fit react-native-google-fit seems to be the most popular option, and and another possible option is to work directly with the Google Fit REST API which I've some experience with.

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

Sponsorship and enterprise-grade support

If you're using @kingstinct/react-native-healthkit to build your production app please consider funding its continued development. It helps us spend more time on keeping this library as good as it can be.

At Kingstinct we're also able to provide enterprise-grade support for this package, find us here or drop an email for more information. Also feel free to join our Discord community.

License

MIT