import { createSignal } from "solid-js"; import { Course } from "../types/Course"; type CourseMap = {[k: number]: Course}; export const [allCourses, setAllCourses] = createSignal>([]); export const [courseMap, setCourseMap] = createSignal({}); (() => { // Get all courses from the API fetch(`${import.meta.env.VITE_BACKEND_URL}/api/course`) .then((res) => res.json()) .then((data: Array) => { setAllCourses(data); const map: CourseMap = {}; for (const course of data) { map[course.course_id] = course; } console.log("course map", map); setCourseMap(map); }); })();