@sanity/ui 0.37.6-next.18 → 0.37.6-next.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/ui",
3
- "version": "0.37.6-next.18+307d9af8",
3
+ "version": "0.37.6-next.19+d4043018",
4
4
  "sideEffects": false,
5
5
  "source": "./src/index.ts",
6
6
  "exports": {
@@ -31,8 +31,8 @@
31
31
  "@juggle/resize-observer": "^3.3.1",
32
32
  "@popperjs/core": "^2.11.2",
33
33
  "@reach/auto-id": "^0.16.0",
34
- "@sanity/color": "2.1.9-next.20+307d9af8",
35
- "@sanity/icons": "1.2.6-next.20+307d9af8",
34
+ "@sanity/color": "2.1.9-next.21+d4043018",
35
+ "@sanity/icons": "1.2.6-next.21+d4043018",
36
36
  "framer-motion": "6.2.8",
37
37
  "popper-max-size-modifier": "^0.2.0",
38
38
  "react-is": "^17.0.2",
@@ -70,5 +70,5 @@
70
70
  "publishConfig": {
71
71
  "access": "public"
72
72
  },
73
- "gitHead": "307d9af862f6cb3fb58a662951e0260804ff7564"
73
+ "gitHead": "d4043018a4091f90775c93e8c5e3335329079917"
74
74
  }
@@ -1,17 +1,19 @@
1
- import {useEffect, useState} from 'react'
1
+ import {useEffect, useMemo, useState} from 'react'
2
2
 
3
3
  /**
4
4
  * @public
5
5
  */
6
6
  export function usePrefersDark(): boolean {
7
- const [dark, setDark] = useState(() => {
8
- if (typeof window === 'undefined') return false
7
+ const mq = useMemo(() => {
8
+ if (typeof window === 'undefined') return undefined
9
9
 
10
- return window.matchMedia('(prefers-color-scheme: dark)').matches
11
- })
10
+ return window.matchMedia('(prefers-color-scheme: dark)')
11
+ }, [])
12
+
13
+ const [dark, setDark] = useState(mq?.matches || false)
12
14
 
13
15
  useEffect(() => {
14
- const mq = window.matchMedia('(prefers-color-scheme: dark)')
16
+ if (!mq) return undefined
15
17
 
16
18
  setDark(mq.matches)
17
19
 
@@ -20,7 +22,7 @@ export function usePrefersDark(): boolean {
20
22
  mq.addEventListener('change', handleChange)
21
23
 
22
24
  return () => mq.removeEventListener('change', handleChange)
23
- }, [])
25
+ }, [mq])
24
26
 
25
27
  return dark
26
28
  }