Skip to content

Commit 60e246b

Browse files
committed
Merge branch 'dev'
2 parents d1ace31 + 13b6a47 commit 60e246b

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/App.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createSignal, For } from "solid-js";
1+
import { createEffect, createSignal, For, onMount } from "solid-js";
22
import { createStore } from "solid-js/store";
33
import toast, { Toaster } from "solid-toast";
44

@@ -90,6 +90,18 @@ const addCourse = async () => {
9090
const App = () => {
9191
const [data, setData] = createSignal("No data fetched!");
9292

93+
onMount(() => {
94+
const localStorageItems: string = localStorage.getItem("courses") || "";
95+
if (localStorageItems?.length > 5) {
96+
setCourses(JSON.parse(localStorageItems));
97+
toast.success("Loaded in Local Data");
98+
}
99+
});
100+
101+
createEffect(() => {
102+
localStorage.setItem("courses", JSON.stringify(courses));
103+
}, courses);
104+
93105
const getData = async () => {
94106
if (courses.length == 0) {
95107
toast.error("Add a course before fetching data!");

0 commit comments

Comments
 (0)