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

@@ -31,30 +31,34 @@ const getFeed = async () => {
let Feed = ({ navigation, route }) => {
let [Posts, setPosts] = useState([]);
console.log("Render Feed");
useEffect(async () => {
let loggedIn = await API.isLoggedIn();
if (!loggedIn) return navigation.reset({
index: 0,
routes: [{ name: 'Login' }],
});
if (route.params && route.params.profileid) {
return navigation.navigate('Profile', { profileid: route.params.profileid })
}
useEffect(() => {
let subscribed = true;
API.getMe().then((me) => {
if (subscribed)
GlobalState.me = me;
});
console.log("Feed from cache")
let cacheFeed = await getFeed() || [];
if (cacheFeed.length && subscribed) setPosts(cacheFeed);
console.log("Feed from server")
let posts = await API.getPosts();
if (subscribed) {
setPosts(posts);
storeFeed(posts);
const getData = async () => {
let loggedIn = await API.isLoggedIn();
if (!loggedIn) return navigation.reset({
index: 0,
routes: [{ name: 'Login' }],
});
if (route.params && route.params.profileid) {
return navigation.navigate('Profile', { profileid: route.params.profileid })
}
API.getMe().then((me) => {
if (subscribed)
GlobalState.me = me;
});
console.log("Feed from cache")
let cacheFeed = await getFeed() || [];
if (cacheFeed.length && subscribed) setPosts(cacheFeed);
console.log("Feed from server")
let posts = await API.getPosts();
if (subscribed) {
setPosts(posts);
storeFeed(posts);
}
console.log("Feed, end useEffect")
}
console.log("Feed, end useEffect")
getData()
return () => {
subscribed = false;
}