Last update to useEffect methods

This commit is contained in:
Adolfo Reyna
2022-11-21 17:25:44 -05:00
parent 7586a20447
commit 5cf38ae6d3
6 changed files with 88 additions and 50 deletions

View File

@@ -32,13 +32,20 @@ let ProfileCard = ({ profileid, hideIcon, profileObj }) => {
let [profile, setProfile] = useState(profileObj || {});
const navigation = useNavigation();
useEffect(async () => {
if (profileObj._id) return 0;
let cacheProfile = await getName(profileid);
if (cacheProfile && cacheProfile.profile) setProfile(cacheProfile);
let p = await API.getUserProfile(profileid).catch(() => { return {} });
setProfile(p);
storeName(profileid, p)
useEffect(() => {
let subscribed = true;
const getData = async () => {
if (profileObj._id) return 0;
let cacheProfile = await getName(profileid);
if (cacheProfile && cacheProfile.profile && subscribed) setProfile(cacheProfile);
let p = await API.getUserProfile(profileid).catch(() => { return {} });
if (subscribed) setProfile(p);
storeName(profileid, p)
};
getData();
return () => {
subscribed = false;
}
}, [profileid]);
let icon = profile._id ? (!profile.isGroup ? "person-outline" : "group") : '';
@@ -53,7 +60,7 @@ let ProfileCard = ({ profileid, hideIcon, profileObj }) => {
return (
<Card style={styles.content}>
<Card.Content>
<Avatar.Image size={150} source={{ uri: photoUrl }} />
<Avatar.Image size={150} source={{ uri: photoUrl }} />
<Title onPress={onPress} numberOfLines={1}>
<Text>
{profile.profile && profile.profile.firstName} {profile.profile && profile.profile.lastName}
@@ -74,7 +81,7 @@ const styles = StyleSheet.create({
margin: 4,
width: "50%",
},
centerItems:{
centerItems: {
justifyContent: 'center',
alignItems: 'center',
}