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
useLocalStorage
useState persisted to localStorage.
A React hook that mirrors useState but persists the value to localStorage as JSON. Reads lazily on mount and writes on every change.
Installation
pnpm dlx shadcn@latest add @frontal-labs/use-local-storage
Usage
import { useLocalStorage } from "@/hooks/use-local-storage";
function ThemeToggle() {
const [theme, setTheme] = useLocalStorage<"light" | "dark">("theme", "light");
return <button onClick={() => setTheme(theme === "light" ? "dark" : "light")}>{theme}</button>;
}Corrupt JSON or unavailable storage falls back to initialValue, and write failures (quota, private mode) fail silently.
API
function useLocalStorage<T>(key: string, initialValue: T): [T, Dispatch<SetStateAction<T>>];Parameters
| Property | Type | Description |
|---|---|---|
key | string | Storage key. Changing it re-persists under the new key. |
initialValue | T | Used when nothing is stored or parsing fails. |
Return value
A [value, setValue] tuple matching useState. setValue accepts updater functions and persists the result as JSON.
On This Page