Yamada UIにスターをあげる

スター
Yamada UIYamada UIv1.5.1

useBreakpointEffect

useBreakpointEffectは、初回のレンダリング時にはエフェクトをスキップし、ブレイクポイントが変更されたときにエフェクトを実行するカスタムフックです。

ソース@yamada-ui/use-breakpoint

インポート

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

使い方

エフェクトは、テーマのブレイクポイントを提供します。

編集可能な例

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

GitHubでこのページを編集する

useTokenuseUpdateEffect