useValue
useValue
is a custom hook that combines useBreakpointValue
and useColorModeValue
.
The current breakpoint is "base"
const breakpoint = useBreakpoint()
const color = useValue({ base: "red", md: "green" })
return <Box color={color}>The current breakpoint is "{breakpoint}"</Box>
If you use this code, you need to add
"use client"
to the top of the file.The current colorMode is "light"
const { colorMode } = useColorMode()
const color = useValue(["green", "red"])
return <Box color={color}>The current colorMode is "{colorMode}"</Box>
If you use this code, you need to add
"use client"
to the top of the file.Usage
import { useValue } from "@yamada-ui/react"
import { useValue } from "@/components/ui"
import { useValue } from "@workspaces/ui"
const color = useValue({ base: "red", md: "green" })
useValue
is using useBreakpointValue and useColorModeValue.