ui: fix usePersistedState erroring when key doesn't exist
This commit is contained in:
parent
1d9927d7f8
commit
89a0244cf2
|
@ -6,7 +6,11 @@ export function usePersistedState<S = undefined> (key: string, defaultValue: S):
|
||||||
try {
|
try {
|
||||||
const item = localStorage.getItem(key);
|
const item = localStorage.getItem(key);
|
||||||
|
|
||||||
return JSON.parse(item || (String(defaultValue)));
|
if (item === null) {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return JSON.parse(item || String(defaultValue));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn('Failed to retrieve persisted value from store.', e);
|
console.warn('Failed to retrieve persisted value from store.', e);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue