How to use the react-native-contacts.updateContact function in react-native-contacts

To help you get started, we’ve selected a few react-native-contacts examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rt2zz / react-native-contacts / example / src / index.js View on Github external
let originalRecord = _.cloneDeep(data[0])
      let pendingRecord = _.cloneDeep(data[0])
      if (originalRecord.familyName) {
        pendingRecord.familyName = (
          originalRecord.familyName
          + Math.floor(Math.random() * 999999)
        ).slice(0, 20)
      } else {
        pendingRecord.familyName = '' + Math.floor(Math.random() * 999)
      }
      pendingRecord.emailAddresses.push({
        email: 'addedFromRNContacts@example.com',
        type: 'work'
      })
console.log('begin updateContact')
      Contacts.updateContact(pendingRecord, (err, data) => {
console.log('updateContact callback')
        if (err) throw err
        Contacts.getAll((err, data) => {
          let updatedRecord = _.find(data, {recordID: originalRecord.recordID})
          console.log('original record:', originalRecord)
          console.log('updated record:', updatedRecord)
          invariant(
            updatedRecord.emailAddresses.length === originalRecord.emailAddresses.length + 1,
            'Email address array is not length one greater than original record'
          )
          invariant(
            updatedRecord.familyName === pendingRecord.familyName,
            'family name was not updated'
          )
        })
      })