@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.
@@ -2764,19 +2764,20 @@ function useMediaIndex() {
2764
2764
  */
2765
2765
 
2766
2766
  function usePrefersDark() {
2767
- const [dark, setDark] = useState(() => {
2768
- if (typeof window === 'undefined') return false;
2769
- return window.matchMedia('(prefers-color-scheme: dark)').matches;
2770
- });
2767
+ const mq = useMemo(() => {
2768
+ if (typeof window === 'undefined') return undefined;
2769
+ return window.matchMedia('(prefers-color-scheme: dark)');
2770
+ }, []);
2771
+ const [dark, setDark] = useState((mq == null ? void 0 : mq.matches) || false);
2771
2772
  useEffect(() => {
2772
- const mq = window.matchMedia('(prefers-color-scheme: dark)');
2773
+ if (!mq) return undefined;
2773
2774
  setDark(mq.matches);
2774
2775
 
2775
2776
  const handleChange = () => setDark(mq.matches);
2776
2777
 
2777
2778
  mq.addEventListener('change', handleChange);
2778
2779
  return () => mq.removeEventListener('change', handleChange);
2779
- }, []);
2780
+ }, [mq]);
2780
2781
  return dark;
2781
2782
  }
2782
2783