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
useIntersectionObserver
Element visibility with IntersectionObserver.
A React hook that reports whether an element is in view. Useful for lazy loading, infinite scroll sentinels, and scroll-triggered animations.
Installation
pnpm dlx shadcn@latest add @frontal-labs/use-intersection-observer
Usage
import { useIntersectionObserver } from "@/hooks/use-intersection-observer";
function LazySection() {
const { ref, isIntersecting } = useIntersectionObserver<HTMLDivElement>({
threshold: 0.5,
});
return <div ref={ref}>{isIntersecting ? <ExpensiveContent /> : null}</div>;
}API
function useIntersectionObserver<T extends HTMLElement>(
options?: IntersectionObserverInit & { enabled?: boolean },
): { ref: RefObject<T | null>; isIntersecting: boolean };Parameters
Accepts all IntersectionObserverInit options (threshold, root, rootMargin) plus:
| 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 observe. |
isIntersecting | boolean | true while the element intersects. Starts at false. |
On This Page