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

@@ -31,13 +31,20 @@ let CourseCard = ({ 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") : '';