🍭 Updates the persistent store to save onload
This commit is contained in:
@@ -4,11 +4,13 @@ import { browser } from '$app/environment';
|
||||
export const persistentStore = <T>(key: string, initialValue: T) => {
|
||||
const savedValue = browser ? localStorage.getItem(key) : null;
|
||||
const data: T = savedValue !== null ? JSON.parse(savedValue) : initialValue;
|
||||
const store = writable<T>(data);
|
||||
const store = writable<T>();
|
||||
|
||||
store.subscribe((value) => {
|
||||
store.subscribe(value => {
|
||||
if (browser) localStorage.setItem(key, JSON.stringify(value));
|
||||
});
|
||||
|
||||
store.set(data);
|
||||
|
||||
return store;
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user