Fixing useEffect warnings
This commit is contained in:
3
API.js
3
API.js
@@ -141,6 +141,9 @@ const API = {
|
||||
getVideo(videoId) {
|
||||
return getCall("/post/video/" + videoId);
|
||||
},
|
||||
registerToken(token) {
|
||||
return postCall("/token/", {token});
|
||||
},
|
||||
deletePost(postid){
|
||||
return deleteCall("/post/" + postid);
|
||||
},
|
||||
|
||||
@@ -31,7 +31,9 @@ const getFeed = async () => {
|
||||
let Feed = ({ navigation, route }) => {
|
||||
let [Posts, setPosts] = useState([]);
|
||||
console.log("Render Feed");
|
||||
useEffect(async () => {
|
||||
useEffect(() => {
|
||||
let subscribed = true;
|
||||
const getData = async () => {
|
||||
let loggedIn = await API.isLoggedIn();
|
||||
if (!loggedIn) return navigation.reset({
|
||||
index: 0,
|
||||
@@ -40,7 +42,6 @@ let Feed = ({ navigation, route }) => {
|
||||
if (route.params && route.params.profileid) {
|
||||
return navigation.navigate('Profile', { profileid: route.params.profileid })
|
||||
}
|
||||
let subscribed = true;
|
||||
API.getMe().then((me) => {
|
||||
if (subscribed)
|
||||
GlobalState.me = me;
|
||||
@@ -55,6 +56,9 @@ let Feed = ({ navigation, route }) => {
|
||||
storeFeed(posts);
|
||||
}
|
||||
console.log("Feed, end useEffect")
|
||||
|
||||
}
|
||||
getData()
|
||||
return () => {
|
||||
subscribed = false;
|
||||
}
|
||||
|
||||
@@ -33,8 +33,9 @@ let Profile = ({ navigation, route }) => {
|
||||
let [Posts, setPosts] = useState([]);
|
||||
let [profile, setProfile] = useState({});
|
||||
|
||||
useEffect(async () => {
|
||||
useEffect(() => {
|
||||
let subscribed = true;
|
||||
const getData = async () => {
|
||||
setPosts([]);
|
||||
if (route.params && route.params.profileid) {
|
||||
console.log('Loading Cache Profile:' + route.params.profileid);
|
||||
@@ -55,6 +56,8 @@ let Profile = ({ navigation, route }) => {
|
||||
} else {
|
||||
navigation.navigate('Feed')
|
||||
}
|
||||
}
|
||||
getData();
|
||||
return ()=>{
|
||||
subscribed = false;
|
||||
}
|
||||
|
||||
@@ -44,13 +44,20 @@ let Media = (props) => {
|
||||
const [videosFiles, setVideosFiles] = useState([]);
|
||||
const [poster, setPoster] = useState('');
|
||||
const [loaded, setLoaded] = useState(false);
|
||||
useEffect(async () => {
|
||||
useEffect(() => {
|
||||
let subscribed = true;
|
||||
let getData = async () => {
|
||||
if (!videosId[1]) return 0;
|
||||
let videoObj = await API.getVideo(videosId[1]);
|
||||
if(videoObj && videoObj.files){
|
||||
if(videoObj && videoObj.files && subscribed){
|
||||
setVideosFiles(videoObj.files);
|
||||
setPoster(videoObj.pictures.sizes[4].link);
|
||||
}
|
||||
};
|
||||
getData();
|
||||
return ()=>{
|
||||
subscribed = false;
|
||||
};
|
||||
}, [props.content])
|
||||
const video = videosFiles.length ? (
|
||||
loaded ? <VideoPlayer videosFiles={videosFiles} poster={poster} videoId={videosId[1]} /> :
|
||||
|
||||
@@ -58,7 +58,7 @@ let Post = (props) => {
|
||||
return (
|
||||
<Card style={styles.card}>
|
||||
<Card.Content>
|
||||
<Hyperlink linkDefault={ true }>
|
||||
<Hyperlink linkDefault={ true } linkStyle={{}}>
|
||||
{!post.nonOrganicType ?
|
||||
<View>
|
||||
<Text style={styles.userName}>
|
||||
|
||||
@@ -28,12 +28,20 @@ let UserName = ({ profileid, hideIcon }) => {
|
||||
let [profile, setProfile] = useState({});
|
||||
const navigation = useNavigation();
|
||||
|
||||
useEffect(async () => {
|
||||
useEffect(() => {
|
||||
let subscribed = true;
|
||||
let getData = async () => {
|
||||
let cacheProfile = await getName(profileid);
|
||||
if (cacheProfile && cacheProfile.profile) setProfile(cacheProfile);
|
||||
if (cacheProfile && cacheProfile.profile && subscribed) 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") : '';
|
||||
|
||||
Reference in New Issue
Block a user