mirror of
https://github.com/yude-jp/yude.jp
synced 2024-12-22 12:10:11 +09:00
Switch button text by theme condition
This commit is contained in:
parent
efaf3180f6
commit
5e068b05ca
@ -13,17 +13,27 @@ const Layout = (props) => {
|
||||
const { locale, locales, defaultLocale, pathname } = router
|
||||
|
||||
const [isMounted, setIsMounted] = useState(false);
|
||||
const { theme, setTheme } = useTheme();
|
||||
useEffect(() => {
|
||||
const { theme, setTheme, getTheme } = useTheme();
|
||||
let moon = "🌙";
|
||||
useEffect(() => {
|
||||
setIsMounted(true);
|
||||
}, []);
|
||||
const switchTheme = () => {
|
||||
const switchTheme = () => {
|
||||
if (isMounted) {
|
||||
setTheme(theme === "light" ? "dark" : "light");
|
||||
}
|
||||
if (theme == "light") moon = "🌙";
|
||||
if (theme == "dark") moon = "🌅";
|
||||
};
|
||||
console.log(theme);
|
||||
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
|
Loading…
Reference in New Issue
Block a user