Leave Yamada UI a star

Star
Yamada UIYamada UIv1.6.4

useBreakpointEffect

useBreakpointEffect is a custom hook that executes a specific callback function when the breakpoint changes.

Source@yamada-ui/use-breakpoint

Import

import { useBreakpointEffect } from "@yamada-ui/react"
Copied!

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>
)
Copied!

Edit this page on GitHub

PrevioususeBreakpointNextuseBreakpointState