mirror of
https://github.com/yude-jp/yude.jp
synced 2024-12-22 20:20:09 +09:00
Switch button text by theme condition
This commit is contained in:
parent
efaf3180f6
commit
5e068b05ca
@ -13,7 +13,8 @@ const Layout = (props) => {
|
|||||||
const { locale, locales, defaultLocale, pathname } = router
|
const { locale, locales, defaultLocale, pathname } = router
|
||||||
|
|
||||||
const [isMounted, setIsMounted] = useState(false);
|
const [isMounted, setIsMounted] = useState(false);
|
||||||
const { theme, setTheme } = useTheme();
|
const { theme, setTheme, getTheme } = useTheme();
|
||||||
|
let moon = "🌙";
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setIsMounted(true);
|
setIsMounted(true);
|
||||||
}, []);
|
}, []);
|
||||||
@ -21,9 +22,18 @@ const switchTheme = () => {
|
|||||||
if (isMounted) {
|
if (isMounted) {
|
||||||
setTheme(theme === "light" ? "dark" : "light");
|
setTheme(theme === "light" ? "dark" : "light");
|
||||||
}
|
}
|
||||||
|
if (theme == "light") moon = "🌙";
|
||||||
|
if (theme == "dark") moon = "🌅";
|
||||||
};
|
};
|
||||||
|
console.log(theme);
|
||||||
return (
|
return (
|
||||||
<button className="my-4 mx-3 text-2xl" onClick={switchTheme}>🌙</button>
|
<button className="my-4 mx-3 text-2xl" onClick={switchTheme}>
|
||||||
|
{theme === 'light' ? (
|
||||||
|
<span>🌙</span>
|
||||||
|
) : (
|
||||||
|
<span>🌄</span>
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
export default Layout
|
export default Layout
|
Loading…
Reference in New Issue
Block a user