We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 008518e commit 5d18397Copy full SHA for 5d18397
1 file changed
src/storage.js
@@ -12,20 +12,9 @@ export interface AsyncStorage {
12
export type Storage = Storage | AsyncStorage
13
14
export const defaultStorage = () => {
15
- try {
16
- if (window && window.localStorage) {
17
- return asyncStorage(window.localStorage)
18
- }
19
- } catch (e) {
20
- if (!(e instanceof ReferenceError)) {
21
- throw e
22
23
24
- console.warn(
25
- `'window.localStorage' unavailable. ` +
26
- `Creating a (not very useful) in-memory storage object as the default storage interface.`
27
- )
28
- return asyncStorage(memStorage())
+ const hasLocalStorage =
+ typeof window !== 'undefined' && 'localStorage' in window
+ return asyncStorage(hasLocalStorage ? window.localStorage : memStorage())
29
}
30
31
/**
0 commit comments