From 041c7737e803066f6a2fba9b0c7749e7cc8a2682 Mon Sep 17 00:00:00 2001 From: Mike Cao Date: Mon, 26 Apr 2021 00:06:08 -0700 Subject: [PATCH] Check user theme preference, closes #555. --- hooks/useTheme.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hooks/useTheme.js b/hooks/useTheme.js index cc610756..46114d43 100644 --- a/hooks/useTheme.js +++ b/hooks/useTheme.js @@ -5,7 +5,8 @@ import { THEME_CONFIG } from 'lib/constants'; import { useEffect } from 'react'; export default function useTheme() { - const theme = useSelector(state => state.app.theme || getItem(THEME_CONFIG) || 'light'); + const defaultTheme = window?.matchMedia('prefers-color-scheme: dark')?.matches ? 'dark' : 'light'; + const theme = useSelector(state => state.app.theme || getItem(THEME_CONFIG) || defaultTheme); const dispatch = useDispatch(); function saveTheme(value) {