Last update to useEffect methods
This commit is contained in:
@@ -43,9 +43,9 @@ const getCourses = async (profileObj) => {
|
||||
});
|
||||
});
|
||||
return {
|
||||
courses: courses.slice(0,10),
|
||||
popular: popular.slice(0,10),
|
||||
watching: watchingArray.slice(0,10),
|
||||
courses: courses.slice(0, 10),
|
||||
popular: popular.slice(0, 10),
|
||||
watching: watchingArray.slice(0, 10),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ const storeCoursesCache = async (value) => {
|
||||
}
|
||||
}
|
||||
|
||||
const getCoursesCache= async () => {
|
||||
const getCoursesCache = async () => {
|
||||
try {
|
||||
const value = await AsyncStorage.getItem('courses')
|
||||
if (value !== null) {
|
||||
@@ -77,19 +77,28 @@ const Courses = () => {
|
||||
const [watching, setWatching] = React.useState([]);
|
||||
const [queryTimer, setQueryTimer] = React.useState(0);
|
||||
|
||||
useEffect(async () => {
|
||||
await getCoursesCache().then((r)=>{
|
||||
console.log("Courses Cache");
|
||||
setGroups(r.courses || []);
|
||||
setPopular(r.popular || []);
|
||||
setWatching(r.watching || []);
|
||||
});
|
||||
let r = await getCourses(viewer);
|
||||
console.log("Courses Live");
|
||||
setGroups(r.courses || []);
|
||||
setPopular(r.popular || []);
|
||||
setWatching(r.watching || []);
|
||||
storeCoursesCache(r);
|
||||
useEffect(() => {
|
||||
let subscribed = true;
|
||||
const getData = async () => {
|
||||
await getCoursesCache().then((r) => {
|
||||
console.log("Courses Cache");
|
||||
setGroups(r.courses || []);
|
||||
setPopular(r.popular || []);
|
||||
setWatching(r.watching || []);
|
||||
});
|
||||
let r = await getCourses(viewer);
|
||||
console.log("Courses Live");
|
||||
if(subscribed){
|
||||
setGroups(r.courses || []);
|
||||
setPopular(r.popular || []);
|
||||
setWatching(r.watching || []);
|
||||
}
|
||||
storeCoursesCache(r);
|
||||
};
|
||||
getData();
|
||||
return () => {
|
||||
subscribed = false;
|
||||
}
|
||||
}, [])
|
||||
|
||||
const onChangeSearch = query => {
|
||||
|
||||
Reference in New Issue
Block a user