Components
- Accordion
- Alert
- Alert Dialog
- Aspect Ratio
- Attachment
- Autocomplete
- Avatar
- Badge
- Breadcrumb
- Bubble
- Button
- Calendar
- Card
- Carousel
- Chart
- Checkbox
- Checkbox Group
- Collapsible
- Combobox
- Command
- Context Menu
- Date Picker
- Dialog
- Drawer
- Dropdown Menu
- Empty
- Field
- Fieldset
- Form
- Frame
- Group
- Input
- Input Group
- Kbd
- Label
- Menu
- Menubar
- Message
- Meter
- Number Field
- OTP Field
- Pagination
- Popover
- Preview Card
- Progress
- Questionnaire
- Radio Group
- Scroll Area
- Select
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Toggle
- Toggle Group
- Toolbar
- Tooltip
Shared
- Artifact
- Audio Player
- Canvas
- Chain of Thought
- Checkpoint
- Code Block
- Commit
- Connection
- Context
- Controls
- Edge
- Environment Variables
- Mic Selector
- Model Selector
- Node
- Node Toolbar
- Open in Chat
- Panel
- Plan
- Prompt Input
- Queue
- Reasoning
- Sandbox
- Schema Display
- Shimmer
- Snippet
- Sources
- Speech Input
- Stack Trace
- Suggestion
- Tool
- Transcription
- Web Preview
Hooks
Resources
useDimensions
Live element size via ResizeObserver.
A React hook that measures an element with ResizeObserver and returns its border-box width and height. Re-renders only when the size changes.
Installation
pnpm dlx shadcn@latest add @frontal-labs/use-dimensions
Usage
import { useDimensions } from "@/hooks/use-dimensions";
function Panel() {
const { ref, dimensions } = useDimensions<HTMLDivElement>();
return (
<div ref={ref}>
{dimensions.width} × {dimensions.height}
</div>
);
}Pass false to pause observing: useDimensions(false).
API
function useDimensions<T extends HTMLElement>(
enabled?: boolean,
): { ref: RefObject<T | null>; dimensions: { width: number; height: number } };Parameters
| Property | Type | Default | Description |
|---|---|---|---|
enabled | boolean | true | Set to false to disconnect the observer. |
Return value
| Property | Type | Description |
|---|---|---|
ref | RefObject<T | null> | Attach to the element to measure. |
dimensions | { width: number; height: number } | Border-box size in pixels. Starts at { width: 0, height: 0 }. |
On This Page