Unable to fetch contacts in my react-native application from phone's contact book

Viewed 2110

I have tried

yarn add react-native-contacts

plugin and followed all steps mentioned in this link

https://github.com/rt2zz/react-native-contacts

but its giving error

undefined is not an object(evaluating Contacts.getAll).

Is there anyother way to fetch contacts from phonebook?Kindly let me know.

Thanks

2 Answers

There is an npm package called "react-native-contacts-wrapper" which does the job wonderfully.

You can add it in your application like this-

import ContactsWrapper from 'react-native-contacts-wrapper';

onContactSelect(){
    ContactsWrapper.getContact()
    .then((contact) => {
        this.setState({
            importingContactInfo:true,
            guest:contact.name,
            email:contact.email,
            phone:contact.phone
        });
    })
    .catch((error) => {
        console.log("ERROR CODE: ", error.code);
        console.log("ERROR MESSAGE: ", error.message);
    });
}
Related