Search code examples
androidreact-nativereact-hooksandroid-permissionsreact-native-contacts

Malformed calls from JS : field sizes are different [[8,39],[4,0]


I want to display the list of contacts on my AVD but Im facing an error (I tried linking the package but it did nothing):

My code :

    const [contact, setContact] = useState([]);
  
    useEffect(() => {
      PermissionsAndroid.request(
        PermissionsAndroid.PERMISSIONS.READ_CONTACTS,
        {
          'title': 'Contacts',
          'message': 'This app would like to view your contacts.'
        }
      ).then(() => {
        Contacts.getAll((err, contacts) => {
          if (err === 'denied'){
            // error
          } else {
            // contacts returned in Array
            setContact(contacts);
            console.log(contact);
          }
        })
      })
      .catch((err)=> {
          console.log(err);
      })
    }, []);

The error :

enter image description here

I searched everywhere for a solution but there's nothing about this issue, thanks for helping me by advance.


Solution

  • The APIs has been updated in version 6. Changing from callback (version 5 uses callback) to promise worked for me. I mean change -

    Contacts.getAll((err, contacts) => { });

    to -

    Contacts.getAll()
        .then((contacts) => {
          // work with contacts
        })
        .catch((e) => { //handle error })