Skip to content

Commit

Permalink
fixed null values (#958) (#959)
Browse files Browse the repository at this point in the history
* fixed null values

* removed unused try catch

Co-authored-by: Zlatko Fedor <[email protected]>
  • Loading branch information
paninaro and seeden authored Aug 22, 2022
1 parent cf0a83c commit 55e776c
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions packages/core/src/hooks/useLocalStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,16 @@ import EventEmitter from '../utils/EventEmitter';
const eventEmitter = new EventEmitter();

function getValueFromLocalStorage<T>(key: string, defaultValue: T) {
try {
// Get from local storage by key
const item = window.localStorage.getItem(key);

if (item !== undefined) {
try {
return JSON.parse(item);
} catch (error) {
return item;
}
}
const item = window.localStorage.getItem(key);

if (item === undefined || item === null) {
return defaultValue;
}

try {
return JSON.parse(item);
} catch (error) {
return defaultValue;
return item;
}
}

Expand Down

0 comments on commit 55e776c

Please sign in to comment.