跳转到内容

useBreakpoint

根据窗口宽度跟踪当前的 Tailwind CSS 断点。

import { useBreakpoint } from 'asterui'
function ResponsiveComponent() {
const { breakpoint, isAbove, isBelow } = useBreakpoint()
return (
<div>
<p>Current breakpoint: {breakpoint}</p>
{isBelow('md') && <MobileNav />}
{isAbove('md') && <DesktopNav />}
</div>
)
}
属性类型描述
breakpointBreakpoint当前断点:'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl'
widthnumber当前窗口宽度(像素)
isAbove(bp)(bp: Breakpoint) => boolean如果当前断点在 bp 或之上则为 true
isBelow(bp)(bp: Breakpoint) => boolean如果当前断点在 bp 之下则为 true
isAt(bp)(bp: Breakpoint) => boolean如果当前断点等于 bp 则为 true
isBetween(min, max)(min: Breakpoint, max: Breakpoint) => boolean如果当前断点在 minmax 之间则为 true
名称最小宽度
xs0px
sm640px
md768px
lg1024px
xl1280px
2xl1536px