useBreakpointEffect
useBreakpointEffect
is a custom hook that executes a specific callback function when the breakpoint changes.
Import
import { useBreakpointEffect } from "@yamada-ui/react"
Usage
The effect provides the theme's breakpoint.
Editable example
const [device, setDevice] = useBreakpointState({ base: "desktop", md: "tablet", sm: "mobile", }) useBreakpointEffect((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