useColorMode
useColorMode
is a custom hook that returns the current color mode.
The current colorMode is "light"
const { colorMode } = useColorMode()
return <Text>The current colorMode is "{colorMode}"</Text>
If you use this code, you need to add
"use client"
to the top of the file.Usage
import { useColorMode } from "@yamada-ui/react"
import { useColorMode } from "@/components/ui"
import { useColorMode } from "@workspaces/ui"
const { changeColorMode, colorMode, internalColorMode, toggleColorMode } =
useColorMode()
Color Mode overview is here.
Switching Color Mode
colorMode
: Provides the current color mode.internalColorMode
: Provides the current color mode includingsystem
.
The current colorMode is "light", internal colorMode is "light"
const { colorMode, internalColorMode, changeColorMode, toggleColorMode } =
useColorMode()
return (
<VStack>
<Text>
The current colorMode is "{colorMode}", internal colorMode is "
{internalColorMode}"
</Text>
<Wrap gap="md">
<Button onClick={() => changeColorMode("light")}>Light Mode</Button>
<Button onClick={() => changeColorMode("dark")}>Dark Mode</Button>
<Button onClick={() => changeColorMode("system")}>System</Button>
<Button onClick={toggleColorMode}>
Switch to {colorMode === "light" ? "Dark" : "Light"} Mode
</Button>
</Wrap>
</VStack>
)
If you use this code, you need to add
"use client"
to the top of the file.