Skip to content

Commit b00790e

Browse files
authored
fix: usePrefersColorScheme window reference breaks nextjs (#907)
* fix usePrefersColorScheme window reference * fix
1 parent 652f266 commit b00790e

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

packages/react/src/hooks/usePrefersColorScheme.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
// issues when used in a NextJS project.
55
import { useEffect, useState } from "react";
66

7-
const darkQuery = window.matchMedia?.("(prefers-color-scheme: dark)");
7+
const darkQuery = window?.matchMedia?.("(prefers-color-scheme: dark)");
88

9-
const lightQuery = window.matchMedia?.("(prefers-color-scheme: light)");
9+
const lightQuery = window?.matchMedia?.("(prefers-color-scheme: light)");
1010

1111
export const usePrefersColorScheme = () => {
1212
const isDark = darkQuery?.matches;
@@ -71,7 +71,7 @@ export const usePrefersColorScheme = () => {
7171
}
7272
}, []);
7373

74-
if (typeof window.matchMedia !== "function") {
74+
if (typeof window?.matchMedia !== "function") {
7575
return preferredColorSchema;
7676
}
7777

0 commit comments

Comments
 (0)