File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed
Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change 1- import { createSignal , For } from "solid-js" ;
1+ import { createEffect , createSignal , For , onMount } from "solid-js" ;
22import { createStore } from "solid-js/store" ;
33import toast , { Toaster } from "solid-toast" ;
44
@@ -90,6 +90,18 @@ const addCourse = async () => {
9090const 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!" ) ;
You can’t perform that action at this time.
0 commit comments