Skip to content

Commit

Permalink
fix: ignore if initial local storage value is corrupted
Browse files Browse the repository at this point in the history
  • Loading branch information
aramalipoor committed Dec 22, 2022
1 parent 4eaaebe commit 1f99cf5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/react/src/common/hooks/useStickyState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ export const useStickyState = <S>(
const stickyValue = supportsLocalStorage
? window?.localStorage.getItem(key)
: null;
return stickyValue !== null ? JSON.parse(stickyValue) : initialState;

try {
return stickyValue !== null && stickyValue !== undefined
? JSON.parse(stickyValue)
: initialState;
} catch (error) {
return initialState;
}
});

React.useEffect(() => {
Expand Down

0 comments on commit 1f99cf5

Please sign in to comment.