I am trying to setup expo contacts to generate the list of contacts on the device. However i am failing to understand and implement it.
The following code doesn't make any change in useEffect and output remain "empty" only.
import React, {useEffect} from 'react'; import { View, Text, StyleSheet } from 'react-native' import { PermissionsAndroid } from 'react-native'; import * as Contacts from 'expo-contacts'; import { FlatList } from 'react-native-gesture-handler'; import { useState } from 'react/cjs/react.development'; export default function Contacts(){ let [contacts, setContacts] = useState(null) let contact = '' useEffect(() => { (async () => { const { status } = await Contacts.requestPermissionsAsync(); if (status === 'granted') { const { data } = await Contacts.getContactsAsync({ fields: [Contacts.Fields.Emails], }); if (data.length > 0) { contact = data[0]; setContacts(data) } } })(); }, []); let output = 'empty' useEffect(() => { if(contacts){ output = 'updated' }else{ output = 'still empty' } }, [contacts]) return ( <View> <Text>{output}</Text> </View> ); }
Any guidance would be appreciated. Thanks
https://stackoverflow.com/questions/66501860/unable-to-generate-flatlist-of-expo-contacts-using-async March 06, 2021 at 10:41AM
没有评论:
发表评论