fix: theme switch on system theme

This commit is contained in:
Refansa 2024-08-03 11:52:59 +07:00
parent f4b3fb54a9
commit 5c9bc7d6d7

View File

@ -25,7 +25,7 @@ export function ThemeSwitch({
}: Props) {
let REACT_TOGGLE_DARK_MODE_GLOBAL_ID = starterId
const { theme, setTheme } = useTheme()
const { theme, systemTheme, setTheme } = useTheme()
const [id, setId] = useState(REACT_TOGGLE_DARK_MODE_GLOBAL_ID)
@ -34,6 +34,13 @@ export function ThemeSwitch({
setId(REACT_TOGGLE_DARK_MODE_GLOBAL_ID)
}, [setId])
useEffect(() => {
// If the theme is currently using system theme, set the theme according to the system theme value.
if (theme === 'system') {
setTheme(systemTheme as 'dark' | 'light')
}
}, [])
const properties = {
circle: {
r: theme === 'dark' ? 9 : 5,