Fix app storage "null" and "undefined" value handling
This commit is contained in:
@@ -52,7 +52,13 @@ function useStorage<T>(
|
|||||||
return initialState;
|
return initialState;
|
||||||
}
|
}
|
||||||
|
|
||||||
return jsonSaveParse(storedValueRaw) ?? storedValueRaw;
|
const parsedValue = jsonSaveParse(storedValueRaw);
|
||||||
|
|
||||||
|
if (storedValueRaw === 'null' || storedValueRaw === 'undefined') {
|
||||||
|
return parsedValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return parsedValue ?? storedValueRaw;
|
||||||
}, [storedValueRaw, key]);
|
}, [storedValueRaw, key]);
|
||||||
|
|
||||||
return [storedValue, setValue];
|
return [storedValue, setValue];
|
||||||
|
|||||||
@@ -17,7 +17,13 @@ export class Storage {
|
|||||||
return defaultValue;
|
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 {
|
getItem(key: string): string | null {
|
||||||
|
|||||||
Reference in New Issue
Block a user