useBreakpointEffect
useBreakpointEffect
is a custom hook that skips the side effect on the initial render and executes a specific callback function when the breakpoint changes.
Import
import { useUpdateBreakpointEffect } from "@yamada-ui/react"
Usage
The effect provides the theme's breakpoint.
Editable example
const [device, setDevice] = useBreakpointState({ base: "desktop", md: "tablet", sm: "mobile", }) useUpdateBreakpointEffect((breakpoint) => { if (breakpoint === "sm") { setDevice("mobile") } else if (breakpoint === "md") { setDevice("tablet") } else { setDevice("desktop") } }, []) return ( <Box bg={{ base: "red.500", xl: "blue.500", lg: "green.500", md: "yellow.500", sm: "purple.500", }} p="md" rounded="md" color="white" transitionProperty="all" transitionDuration="slower" > The current device is "{device}" </Box> )
If you want to learn more about responsive styles, please check here.
Edit this page on GitHub