mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-30 02:12:22 +03:00
23 lines
630 B
TypeScript
23 lines
630 B
TypeScript
import { useEffect, useState } from 'react';
|
|
import useTermState from '../state';
|
|
|
|
export function useDark() {
|
|
const [osDark, setOsDark] = useState(false);
|
|
|
|
useEffect(() => {
|
|
const themeWatcher = window.matchMedia('(prefers-color-scheme: dark)');
|
|
const update = (e: MediaQueryListEvent) => {
|
|
setOsDark(e.matches);
|
|
};
|
|
setOsDark(themeWatcher.matches);
|
|
themeWatcher.addEventListener('change', update);
|
|
|
|
return () => {
|
|
themeWatcher.removeEventListener('change', update);
|
|
};
|
|
}, []);
|
|
|
|
const theme = useTermState(s => s.theme);
|
|
return theme === 'dark' || (osDark && theme === 'auto');
|
|
}
|