Skip to content

Commit 5d18397

Browse files
committed
Remove localStorage warning.
1 parent 008518e commit 5d18397

1 file changed

Lines changed: 3 additions & 14 deletions

File tree

src/storage.js

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,9 @@ export interface AsyncStorage {
1212
export type Storage = Storage | AsyncStorage
1313

1414
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())
15+
const hasLocalStorage =
16+
typeof window !== 'undefined' && 'localStorage' in window
17+
return asyncStorage(hasLocalStorage ? window.localStorage : memStorage())
2918
}
3019

3120
/**

0 commit comments

Comments
 (0)