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