mirror of
https://github.com/yude-jp/yude.jp
synced 2024-12-23 04:30:11 +09:00
35 lines
976 B
JavaScript
35 lines
976 B
JavaScript
import Head from "next/head"
|
|
import Link from "next/link"
|
|
import "tailwindcss/tailwind.css";
|
|
import useTranslation from 'next-translate/useTranslation'
|
|
import { useRouter } from 'next/router'
|
|
import React, { useEffect, useState } from 'react'
|
|
import { useTheme } from "next-themes";
|
|
|
|
const Layout = (props) => {
|
|
const { title, children } = props
|
|
const siteTitle = "yude.jp"
|
|
const router = useRouter()
|
|
const { locale, locales, defaultLocale, pathname } = router
|
|
|
|
const [isMounted, setIsMounted] = useState(false);
|
|
const { theme, setTheme, getTheme } = useTheme();
|
|
useEffect(() => {
|
|
setIsMounted(true);
|
|
}, []);
|
|
const switchTheme = () => {
|
|
if (isMounted) {
|
|
setTheme(theme === "light" ? "dark" : "light");
|
|
}
|
|
};
|
|
return (
|
|
<button className="my-4 text-2xl" onClick={switchTheme}>
|
|
{theme === 'light' ? (
|
|
<span>🌙</span>
|
|
) : (
|
|
<span>🌄</span>
|
|
)}
|
|
</button>
|
|
)
|
|
}
|
|
export default Layout |