cal.pub0.org/components/Theme.tsx

18 lines
432 B
TypeScript
Raw Normal View History

2021-07-11 19:35:56 +00:00
import { useEffect, useState } from "react";
2021-07-11 19:35:56 +00:00
export default function Theme(theme?: string) {
const [isReady, setIsReady] = useState(false);
2021-07-11 19:35:56 +00:00
useEffect(() => {
if (!theme && window.matchMedia("(prefers-color-scheme: dark)").matches) {
document.documentElement.classList.add("dark");
} else {
document.documentElement.classList.add(theme);
}
setIsReady(true);
}, []);
return {
2021-07-11 19:35:56 +00:00
isReady,
};
}