feat: draft update ui

This commit is contained in:
2026-09-17 06:11:14 +08:00
parent de0666beb1
commit aa25af028e
9 changed files with 450 additions and 79 deletions
+23
View File
@@ -0,0 +1,23 @@
import { useEffect, useState } from "react";
export function useLocalStorage<T = unknown>(key: string, initialValue: T) {
const [state, setState] = useState<T>(() => {
try {
const item = window.localStorage.getItem(key);
return item ? JSON.parse(item) : initialValue;
} catch (error) {
console.log(error);
return initialValue;
}
});
useEffect(() => {
try {
window.localStorage.setItem(key, JSON.stringify(state));
} catch (error) {
console.log(error);
}
}, [state]);
return [state, setState] as const;
}