2021-07-11 19:35:56 +00:00
|
|
|
import { useEffect, useState } from "react";
|
2021-07-09 22:59:21 +00:00
|
|
|
|
2021-07-11 19:35:56 +00:00
|
|
|
export default function Theme(theme?: string) {
|
2021-07-09 22:59:21 +00:00
|
|
|
const [isReady, setIsReady] = useState(false);
|
2021-07-11 19:35:56 +00:00
|
|
|
useEffect(() => {
|
2021-07-09 22:59:21 +00:00
|
|
|
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,
|
|
|
|
};
|
|
|
|
}
|