Skip to content

Commit

Permalink
fix(ThemeToggle): make it work in both pages & app router
Browse files Browse the repository at this point in the history
  • Loading branch information
BrickheadJohnny committed Jul 11, 2024
1 parent 8b4b437 commit d6e4fc5
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/v2/components/ThemeToggle.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
"use client"

import { ToggleGroup, ToggleGroupItem } from "@/components/ui/ToggleGroup"
import { useColorMode } from "@chakra-ui/react"
import { Desktop, Moon, Sun } from "@phosphor-icons/react/dist/ssr"
import { useTheme } from "next-themes"
import { useIsClient } from "usehooks-ts"
import { useIsClient, useLocalStorage } from "usehooks-ts"

export function ThemeToggle() {
const { setTheme, theme } = useTheme()
const isClient = useIsClient()
const { colorMode: chakraColorMode, setColorMode: setChakraColorMode } =
useColorMode()

if (!isClient) {
return
Expand All @@ -16,9 +19,13 @@ export function ThemeToggle() {
return (
<ToggleGroup
type="single"
value={theme}
value={chakraColorMode || theme}
onValueChange={(selected) => {
if (selected) setTheme(selected)
if (selected) {
console.log("selected", selected)
setTheme(selected)
if (typeof setChakraColorMode === "function") setChakraColorMode(selected)
}
}}
aria-label="Toggle between themes"
>
Expand Down

0 comments on commit d6e4fc5

Please sign in to comment.