useBreakpointState
useBreakpointState
is a custom hook that takes a responsive object as an initial state and returns a state corresponding to the current breakpoint.
const [value, setValue] = useBreakpointState({ base: 1, md: 2 })
return (
<Button onClick={() => setValue((prev) => prev + 1)}>
The current value is "{value}"
</Button>
)
If you use this code, you need to add
"use client"
to the top of the file.Usage
import { useBreakpointState } from "@yamada-ui/react"
import { useBreakpointState } from "@/components/ui"
import { useBreakpointState } from "@workspaces/ui"
const [value, setValue] = useBreakpointState({ base: 1, md: 2 })