mirror of
https://github.com/Tony0410/readlater.git
synced 2026-05-24 13:52:03 +08:00
Fix localStorage to merge with defaults for new fields
Old saved settings were missing new edgeUrl field, causing Edge TTS to fail. Now merges stored values with defaults so new fields are included. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -10,13 +10,15 @@ export function useLocalStorage<T>(key: string, initialValue: T): [T, (value: T
|
||||
try {
|
||||
const item = window.localStorage.getItem(key);
|
||||
if (item) {
|
||||
setStoredValue(JSON.parse(item));
|
||||
// Merge stored value with defaults to handle new fields
|
||||
const parsed = JSON.parse(item);
|
||||
setStoredValue({ ...initialValue, ...parsed });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error reading localStorage key "${key}":`, error);
|
||||
}
|
||||
setIsHydrated(true);
|
||||
}, [key]);
|
||||
}, [key, initialValue]);
|
||||
|
||||
const setValue = (value: T | ((prev: T) => T)) => {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user