useLocalStorage

Hook

Like useState, but persists the value in localStorage. SSR-safe.

npx arupui add use-local-storage

Usage

use-local-storage.tsx
import { useLocalStorage } from "@/hooks/use-local-storage"

function Settings() {
  const [theme, setTheme] = useLocalStorage("theme", "light")

  return (
    <button onClick={() => setTheme(t => t === "light" ? "dark" : "light")}>
      Current: {theme}
    </button>
  )
}

Parameters

keystring

localStorage key

initialValueT

Default value if key doesn't exist

Returns

[T, (value: T | (val: T) => T) => void]
Theme Editor

Theme

Radius0.5rem
Letter Spacing0em

Colors

light