React Native Contacts

8.0.10 · active · verified Sun Apr 19

React Native Contacts is a JavaScript library for React Native applications, providing cross-platform access to the device's contact list on both Android and iOS. The current stable version is 8.0.10. While not on a fixed release schedule, the library sees regular maintenance and bug fixes, with recent updates (like v8.0.0) focusing on compatibility with the new React Native architecture (TurboModules and Fabric). It also provides fixes for compatibility with older legacy bridge projects (v8.0.9, v8.0.10). Key differentiators include its long-standing support for both major mobile platforms, straightforward API for retrieving, adding, and updating contacts, and handling of native permissions. Users should be aware of performance considerations when using `getAll` and specific installation steps tailored for different React Native versions and architectures.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to request Android runtime permissions for contacts and then fetch all contacts using `Contacts.getAll()`.

import { PermissionsAndroid } from 'react-native';
import Contacts from 'react-native-contacts';

const fetchContacts = async () => {
  try {
    const granted = await PermissionsAndroid.request(
      PermissionsAndroid.PERMISSIONS.READ_CONTACTS,
      {
        title: 'Contacts',
        message: 'This app would like to view your contacts.',
        buttonPositive: 'Please accept bare mortal',
      }
    );
    if (granted === PermissionsAndroid.RESULTS.GRANTED) {
      console.log('Contacts permission granted.');
      const contacts = await Contacts.getAll();
      console.log('Fetched contacts:', contacts.slice(0, 3)); // Log first 3 contacts
      // Example: Access a specific contact's phone number
      if (contacts.length > 0 && contacts[0].phoneNumbers && contacts[0].phoneNumbers.length > 0) {
        console.log('First contact phone number:', contacts[0].phoneNumbers[0].number);
      }
    } else {
      console.log('Contacts permission denied.');
    }
  } catch (err) {
    console.error('Error fetching contacts:', err);
  }
};

fetchContacts();

view raw JSON →