Fix app storage "null" and "undefined" value handling

This commit is contained in:
schroda
2025-08-21 03:57:47 +02:00
parent 414211ae74
commit bfb10ad204
2 changed files with 14 additions and 2 deletions

View File

@@ -52,7 +52,13 @@ function useStorage<T>(
return initialState;
}
return jsonSaveParse(storedValueRaw) ?? storedValueRaw;
const parsedValue = jsonSaveParse(storedValueRaw);
if (storedValueRaw === 'null' || storedValueRaw === 'undefined') {
return parsedValue;
}
return parsedValue ?? storedValueRaw;
}, [storedValueRaw, key]);
return [storedValue, setValue];

View File

@@ -17,7 +17,13 @@ export class Storage {
return defaultValue;
}
return jsonSaveParse(value) ?? (value as T);
const parsedValue = jsonSaveParse(value);
if (value === 'null' || value === 'undefined') {
return parsedValue;
}
return parsedValue ?? (value as T);
}
getItem(key: string): string | null {