[FE] Cache the course list
This commit is contained in:
parent
3827605a36
commit
89dc57daa8
@ -85,8 +85,15 @@ function CoursesProvider(props: {courses: Resource<Course[]>, children: JSX.Elem
|
||||
);
|
||||
}
|
||||
|
||||
let cachedCourses: Array<Course> | null = null;
|
||||
|
||||
async function fetchAllCourses(): Promise<Array<Course>> {
|
||||
if (cachedCourses !== null) {
|
||||
return cachedCourses;
|
||||
}
|
||||
|
||||
const result = await axios.get<Array<Course>>(`${import.meta.env.VITE_BACKEND_URL}/api/course`);
|
||||
cachedCourses = result.data;
|
||||
return result.data;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user