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) 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") : '';
@@ -65,7 +72,7 @@ let ProfileCard = ({ profileid, hideIcon, profileObj }) => {
<Text>
<FollowButton profile={profile} />
<Text><Icon name={"hail"} size={18} />
{Object.keys(profile.subscribed).length}</Text>
{Object.keys(profile.subscribed).length}</Text>
</Text>
</Card.Content>
</Card>