mirror of
https://github.com/MewoLab/AquaDX.git
synced 2026-02-09 07:17:26 +08:00
[+] Setting of score rounding and fix bugs
This commit is contained in:
24
AquaNet/src/libs/hooks/useLocalStorage.svelte.ts
Normal file
24
AquaNet/src/libs/hooks/useLocalStorage.svelte.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
const useLocalStorage = <T>(key: string, initialValue: T) => {
|
||||
let value = initialValue;
|
||||
|
||||
const currentValue = localStorage.getItem(key);
|
||||
if (currentValue) value = JSON.parse(currentValue);
|
||||
|
||||
const save = () => {
|
||||
localStorage.setItem(key, JSON.stringify(value));
|
||||
};
|
||||
|
||||
return {
|
||||
get value() {
|
||||
return value;
|
||||
},
|
||||
set value(v: T) {
|
||||
value = v;
|
||||
save();
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export default useLocalStorage;
|
||||
Reference in New Issue
Block a user