HextaUI

Resizable: Remember the layout

useDefaultLayout saves sizes to localStorage and restores them on the next visit without animating in. Give each panel an id.

Resize me, then reload
Detail
"use client"

import {
  ResizableHandle,
  ResizablePanel,
  ResizablePanelGroup,
  useDefaultLayout,
} from "@/components/ui/resizable"

export function ResizablePersist() {
  const { defaultLayout, onLayoutChanged } = useDefaultLayout({
    id: "hextaui-resizable-persist",
  })

  return (
    <div className="h-56 w-full max-w-md overflow-hidden rounded-xl border">
      <ResizablePanelGroup
        defaultLayout={defaultLayout}
        onLayoutChanged={onLayoutChanged}
      >
        <ResizablePanel id="list" defaultSize="40%" minSize="20%">
          <div className="flex h-full items-center justify-center p-4 text-center text-sm font-medium">
            Resize me, then reload
          </div>
        </ResizablePanel>
        <ResizableHandle />
        <ResizablePanel id="detail" minSize="20%">
          <div className="flex h-full items-center justify-center text-sm font-medium">
            Detail
          </div>
        </ResizablePanel>
      </ResizablePanelGroup>
    </div>
  )
}

This adds the example as components/examples/resizable/persist.tsx, together with the Resizable component and the HextaUI theme tokens it needs.

pnpm dlx shadcn@latest add https://hextaui.com/r/resizable-persist.json

To add only the component, follow the Resizable installation.

Props in this example

The Resizable props this example sets, from the API reference.

PropTypeDefault
defaultLayout
Layout–
onLayoutChangedOnce a change settles.
(layout, meta) => void–
PropTypeDefault
defaultSize
number | string–
minSize
number | string–
idNeeded to remember layouts.
string–

Every prop is in the Resizable API reference.

See them all, with keyboard support and accessibility notes, on the Resizable page.