Loading...
Please waitLoading...
Please waitDetect and respond to changes in viewport size with the useBreakpoint hook, allowing for responsive design adjustments.
pnpm dlx shadcn@latest add https://usekit.kiron.dev/k/use-breakpoint
"use client"
import * as React from "react"
import { useBreakpoint } from "@/hooks/use-breakpoint"
export function Component() {
const { currentBreakpoint, isAbove } = useBreakpoint()
return (
<div>
<h2>Current Breakpoint: {currentBreakpoint}</h2>
<div
style={{
padding: isAbove("xl") ? "40px" : "20px",
fontSize: isAbove("2xl") ? "24px" : "16px",
backgroundColor: isAbove("lg") ? "#e3f2fd" : "#fff8e1",
}}
>
{isAbove("2xl")
? "Extra Large Desktop View"
: isAbove("xl")
? "Desktop View"
: isAbove("lg")
? "Laptop View"
: isAbove("md")
? "Tablet View"
: "Mobile View"}
</div>
</div>
)
}
Name | Type | Description | Default Value | Optional |
---|---|---|---|---|
breakpoints | Partial<Record<Breakpoint, number>> | Custom breakpoints to override the default values. | {} | Yes |
Name | Type | Description |
---|---|---|
currentBreakpoint | Breakpoint | null | The current breakpoint based on the viewport width. Returns null if no breakpoints match. |
isAbove | (breakpoint: Breakpoint) => boolean | Function to check if the current viewport width is above the specified breakpoint. |
isBelow | (breakpoint: Breakpoint) => boolean | Function to check if the current viewport width is below the specified breakpoint. |
This item responds to screen size changes
This item responds to screen size changes
This item responds to screen size changes
This item responds to screen size changes
This item responds to screen size changes
This item responds to screen size changes
This element changes its padding and font size based on breakpoints. Current breakpoint:
This warning only appears on small screens