Fixing useEffect warnings

This commit is contained in:
aeroreyna
2022-11-19 20:45:32 -05:00
parent 4e1112fbf4
commit a313822c27
6 changed files with 81 additions and 56 deletions

View File

@@ -33,28 +33,31 @@ let Profile = ({ navigation, route }) => {
let [Posts, setPosts] = useState([]);
let [profile, setProfile] = useState({});
useEffect(async () => {
useEffect(() => {
let subscribed = true;
setPosts([]);
if (route.params && route.params.profileid) {
console.log('Loading Cache Profile:' + route.params.profileid);
await API.getUserProfile(route.params.profileid).then((profileObj) => {
if(!subscribed) return 0;
let profile = profileObj.profile
setProfile(profileObj);
navigation.setOptions({ title: profile.firstName + " " + profile.lastName });
});
await getProfilePosts(route.params.profileid).then(setPosts);
console.log('Loaded Cache Profile:' + route.params.profileid);
API.getPosts(route.params.profileid).then((data) => {
if(!subscribed) return 0;
setPosts(data);
storeProfilePosts(route.params.profileid, data);
console.log('Store Cache Profile:' + route.params.profileid);
});
} else {
navigation.navigate('Feed')
const getData = async () => {
setPosts([]);
if (route.params && route.params.profileid) {
console.log('Loading Cache Profile:' + route.params.profileid);
await API.getUserProfile(route.params.profileid).then((profileObj) => {
if(!subscribed) return 0;
let profile = profileObj.profile
setProfile(profileObj);
navigation.setOptions({ title: profile.firstName + " " + profile.lastName });
});
await getProfilePosts(route.params.profileid).then(setPosts);
console.log('Loaded Cache Profile:' + route.params.profileid);
API.getPosts(route.params.profileid).then((data) => {
if(!subscribed) return 0;
setPosts(data);
storeProfilePosts(route.params.profileid, data);
console.log('Store Cache Profile:' + route.params.profileid);
});
} else {
navigation.navigate('Feed')
}
}
getData();
return ()=>{
subscribed = false;
}