3

I'm tryna get the contacts list of the device but react-native-contacts returns undefined.

enter image description here

I've Installed the package and linked it as mentioned in the project's GitHub page https://github.com/rt2zz/react-native-contacts

I've also added the permissions to the android-manifest file. How do I get it works

BaHaa Jr.
  • 534
  • 1
  • 7
  • 19

2 Answers2

4

This happens mostly because of the linking-step was missing as there are native modules required:

After npm install react-native-contacts (or yarn add) you are required to link the stuff with

react-native link react-native-contacts

Afterwards you need to rebuild your project (react-native run-android or build in Android Studio). Just to "Reload" in Simulator or on Device is not sufficient after linking a native library.

Also some more permissions needs to be placed in AndroidManifest.xml:

<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
itinance
  • 11,711
  • 7
  • 58
  • 98
0

My stack :

  • react-native: 0.45.1
  • react-native-contacts: ^1.0.0"

I was still getting the error after linking the module as specified above. Finally resolved the issue after adding the following to ReactNativeContacts.java (/node_modules/react-native-contacts/android/src/main/java/com/rt2zz/reactnativecontacts):

import com.facebook.react.bridge.JavaScriptModule;

@override public List<Class<? extends JavaScriptModule>> createJSModules() { return Collections.emptyList(); }
stealththeninja
  • 3,576
  • 1
  • 26
  • 44
Marus
  • 1
  • 1