Every time I open a certain page in my app it gives me error Can't perform a react state on an unmounted component, it indicates a memory leak.. how can i fix that? the page is a profile page i fetch the user data and the posts, it contains a React Native Tab View, here's how i fetch the data
useEffect(() => {
const { currentUser, posts } = props;
if (props.route.params.uid === firebase.auth().currentUser.uid) {
setUser(currentUser);
setUserPosts([]);
} else {
firebase
.firestore()
.collection('Users')
.doc(props.route.params.uid)
.get()
.then((snapshot) => {
if (snapshot.exists) {
setUser(snapshot.data());
} else {
console.log('does not exist');
}
});
firebase
.firestore()
.collection('Users')
.doc(props.route.params.uid)
.collection('userPosts')
.orderBy('creation', 'desc')
.get()
.then((snapshot) => {
let posts = snapshot.docs.map((doc) => {
const data = doc.data();
const id = doc.id;
return { id, ...data };
});
setUserPosts(posts);
});
}
if (props.following.indexOf(props.route.params.uid) > -1) {
setFollowing(true);
} else {
setFollowing(false);
}
}, [props.route.params.uid, props.following]);