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