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