MCPcopy Create free account
hub / github.com/code-forge-io/react-router-devtools / ThemeToggle

Function ThemeToggle

docs/app/components/theme-toggle.tsx:5–31  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3import { applyTheme, getCurrentTheme } from "~/utils/theme"
4
5export function ThemeToggle() {
6 const [theme, setTheme] = useState<"light" | "dark" | null>(null)
7
8 useLayoutEffect(() => {
9 setTheme(getCurrentTheme())
10 }, [])
11
12 const toggle = () => {
13 if (!theme) return
14 const next = theme === "dark" ? "light" : "dark"
15 applyTheme(next)
16 setTheme(next)
17 }
18
19 if (theme === null) {
20 return <IconButton aria-label="Loading theme..." name="SunMoon" />
21 }
22
23 const isDarkTheme = theme === "dark"
24 return (
25 <IconButton
26 aria-label={`Switch to ${isDarkTheme ? "light" : "dark"} mode`}
27 name={isDarkTheme ? "Moon" : "Sun"}
28 onClick={toggle}
29 />
30 )
31}

Callers

nothing calls this directly

Calls 1

getCurrentThemeFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…