File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -5,11 +5,18 @@ import { useThemeUI } from './context'
5
5
import { createColorStyles } from './custom-properties'
6
6
7
7
const STORAGE_KEY = 'theme-ui-color-mode'
8
- const HAS_STORAGE = typeof Storage !== 'undefined'
8
+ const hasStorage = ( ) => {
9
+ try {
10
+ return typeof window . localStorage !== undefined
11
+ } catch ( e ) {
12
+ return false
13
+ }
14
+ }
9
15
10
16
const storage = {
11
- get : init => HAS_STORAGE && window . localStorage . getItem ( STORAGE_KEY ) || init ,
12
- set : value => HAS_STORAGE && window . localStorage . setItem ( STORAGE_KEY , value ) ,
17
+ get : init =>
18
+ ( hasStorage ( ) && window . localStorage . getItem ( STORAGE_KEY ) ) || init ,
19
+ set : value => hasStorage ( ) && window . localStorage . setItem ( STORAGE_KEY , value ) ,
13
20
}
14
21
15
22
export const getMediaQuery = ( ) => {
You can’t perform that action at this time.
0 commit comments