mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2025-04-27 16:16:21 -04:00
toggle is still flashing, try reverting to importing dynamically...?
This commit is contained in:
parent
17375ef876
commit
3528707e52
@ -1,9 +1,12 @@
|
|||||||
|
import dynamic from "next/dynamic";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import ThemeToggle from "./ThemeToggle";
|
|
||||||
import { HomeIcon, NotesIcon, ProjectsIcon, ContactIcon } from "../icons";
|
import { HomeIcon, NotesIcon, ProjectsIcon, ContactIcon } from "../icons";
|
||||||
|
|
||||||
import styles from "./Menu.module.scss";
|
import styles from "./Menu.module.scss";
|
||||||
|
|
||||||
|
// ensure the theme toggle isn't evaluated server-side
|
||||||
|
const ThemeToggle = dynamic(() => import("./ThemeToggle"), { ssr: false });
|
||||||
|
|
||||||
const links = [
|
const links = [
|
||||||
{
|
{
|
||||||
icon: <HomeIcon className={`icon ${styles.icon}`} />,
|
icon: <HomeIcon className={`icon ${styles.icon}`} />,
|
||||||
|
@ -1,19 +1,9 @@
|
|||||||
import { useState, useEffect } from "react";
|
|
||||||
import { useTheme } from "next-themes";
|
import { useTheme } from "next-themes";
|
||||||
import { BulbOffIcon, BulbOnIcon } from "../icons";
|
import { BulbOffIcon, BulbOnIcon } from "../icons";
|
||||||
|
|
||||||
const ThemeToggle = ({ className = "" }) => {
|
const ThemeToggle = ({ className = "" }) => {
|
||||||
const [mounted, setMounted] = useState(false);
|
|
||||||
const { resolvedTheme, setTheme } = useTheme();
|
const { resolvedTheme, setTheme } = useTheme();
|
||||||
|
|
||||||
// avoid hydration mismatch:
|
|
||||||
// https://github.com/pacocoursey/next-themes#avoid-hydration-mismatch
|
|
||||||
useEffect(() => setMounted(true), []);
|
|
||||||
if (!mounted) {
|
|
||||||
// always return one of the bulbs just so there are never flashing layout shifts
|
|
||||||
return <BulbOffIcon className={`icon ${className}`} />;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
onClick={() => setTheme(resolvedTheme === "dark" ? "light" : "dark")}
|
onClick={() => setTheme(resolvedTheme === "dark" ? "light" : "dark")}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user