From 0096f6daf2ee4dd3961366844f491d100f989dfb Mon Sep 17 00:00:00 2001 From: Damian Date: Mon, 2 Dec 2024 16:07:11 -0500 Subject: [PATCH] Fix cookie error --- components/CreatePlan.tsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/components/CreatePlan.tsx b/components/CreatePlan.tsx index 321782e..70b169b 100644 --- a/components/CreatePlan.tsx +++ b/components/CreatePlan.tsx @@ -76,7 +76,9 @@ export default function CreatePlan(props: any) { } async function updateLocalPlan() { const planCourses: any = await getPlanCourses1(); - setCourses(planCourses.courses); + if (planCourses) { + setCourses(planCourses?.courses); + } if (scrollRef.current) { scrollRef.current.scrollTop = scrollRef.current.scrollHeight; } @@ -119,15 +121,17 @@ export default function CreatePlan(props: any) { useEffect(() => { setSelectedCoursePlan([cookies.get("plan")]); - if (props.initialPlan.courses) { - setCourses(props.initialPlan.courses); + if (props.initialPlan && props.initialPlan.length > 0) { + if (props.initialPlan.courses && props.initalPlan.courses.length > 0) { + setCourses(props.initialPlan.courses); + } } }, [props.initialPlan, cookies.get("plan")]); const CoursesList = () => { const output: any = []; - if (courses) { + if (courses && courses != undefined) { return courses.map((course: any) => (