Skip to content

Commit

Permalink
๐Ÿ› ๏ธ Fix localStorage exceeded the quota error (#1052)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimlbc committed Jan 5, 2023
1 parent d4d03c7 commit 05f1a7f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/hip-pumpkins-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@usedapp/core': patch
---

Fix writing to local storage crashing application
9 changes: 7 additions & 2 deletions packages/core/src/hooks/useLocalStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ function setItem(key: string, value: any, storage: WindowLocalStorage['localStor
storage.removeItem(key)
} else {
const toStore = JSON.stringify(value)
storage.setItem(key, toStore)
return JSON.parse(toStore)
try {
storage.setItem(key, toStore)
return JSON.parse(toStore)
} catch (err) {
console.error('Error in localStorage', err)
storage.removeItem(key)
}
}
}

Expand Down

2 comments on commit 05f1a7f

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๐ŸŽ‰ Published on https://example.usedapp.io as production
๐Ÿš€ Deployed on https://63b6f4db39a2e226721fc05a--usedapp-example.netlify.app

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๐ŸŽ‰ Published on https://usedapp.io as production
๐Ÿš€ Deployed on https://63b6f4e4890d962503a3ade6--usedapp-website.netlify.app

Please sign in to comment.