Skip to main content

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.

queryQuantitySamples

Query quantity samples for a specific quantity type identifier.
queryQuantitySamples(
  identifier: QuantityTypeIdentifier,
  options: QueryOptionsWithSortOrderAndUnit
): Promise<readonly QuantitySample[]>
identifier
QuantityTypeIdentifier
required
The quantity type identifier to query (e.g., 'HKQuantityTypeIdentifierStepCount', 'HKQuantityTypeIdentifierHeartRate')
options
QueryOptionsWithSortOrderAndUnit
required
Query options for filtering and controlling the results

Returns

samples
QuantitySample[]
An array of quantity samples matching the query criteria

Example

import { queryQuantitySamples } from '@kingstinct/react-native-healthkit'

// Query last 7 days of step count
const stepSamples = await queryQuantitySamples(
  'HKQuantityTypeIdentifierStepCount',
  {
    limit: 100,
    ascending: false,
    filter: {
      date: {
        startDate: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000),
        endDate: new Date()
      }
    }
  }
)

console.log(`Found ${stepSamples.length} step samples`)
stepSamples.forEach(sample => {
  console.log(`${sample.quantity} ${sample.unit} on ${sample.startDate}`)
})

queryQuantitySamplesWithAnchor

Query quantity samples using HealthKit anchors for efficient syncing. This method is ideal for keeping your app’s data in sync with HealthKit, as it returns only the samples that have changed since the last query.
queryQuantitySamplesWithAnchor(
  identifier: QuantityTypeIdentifier,
  options: QueryOptionsWithAnchorAndUnit
): Promise<QuantitySamplesWithAnchorResponse>
identifier
QuantityTypeIdentifier
required
The quantity type identifier to query
options
QueryOptionsWithAnchorAndUnit
required
Query options including anchor information

Returns

response
QuantitySamplesWithAnchorResponse
An object containing samples, deleted samples, and the new anchor

Example

import { queryQuantitySamplesWithAnchor } from '@kingstinct/react-native-healthkit'

// First sync - no anchor
const { newAnchor, samples, deletedSamples } = await queryQuantitySamplesWithAnchor(
  'HKQuantityTypeIdentifierStepCount',
  {
    limit: 100
  }
)

console.log(`Initial sync: ${samples.length} samples`)

// Store the anchor for next time
const storedAnchor = newAnchor

// Later, sync only changes
const nextResult = await queryQuantitySamplesWithAnchor(
  'HKQuantityTypeIdentifierStepCount',
  {
    limit: 100,
    anchor: storedAnchor
  }
)

console.log(`New samples: ${nextResult.samples.length}`)
console.log(`Deleted samples: ${nextResult.deletedSamples.length}`)
Always store the newAnchor value after each successful sync. Use this anchor in subsequent queries to retrieve only the changes since the last sync.
Setting limit: 0 will return all available samples, but for large datasets, it’s recommended to use a reasonable limit and paginate through results using the anchor.

Build docs developers (and LLMs) love