usePanel
Scoped hook for reading and mutating a single panel.
usePanel is the primary hook for interacting with a panel. It returns the panel's current state and a set of actions scoped to that panel. The component re-renders only when this panel's slice of the layout tree changes — not on unrelated mutations elsewhere.
Signature
panel
The current panel node from the layout tree, or null if the panel has been removed. Always check for null before reading panel fields.
setActiveTab
Activates a tab by id. Does nothing if the tab is already active.
addTab
Adds a new tab to the panel.
| Option | Default | Description |
|---|---|---|
activate | false | Switch to the new tab immediately after adding. |
index | end | Insert position in the tab list. |
removeTab
Removes a tab by id. If it was the active tab, the nearest sibling becomes active.
reorderTab
Moves a tab to a new position within the same panel. Useful for implementing drag-to-reorder within a tab bar.
split
SplitTarget is 'right' | 'bottom' | 'left' | 'top'. See SplitTarget in the types reference.
Splits the panel in the given direction, creating a new empty panel alongside it. The new panel gets a copy of the current panel's active tab type.
toggleCollapse
Collapses or expands the panel. Pass an explicit boolean to force a specific state; omit it to toggle.
When collapsed, the panel renders at a fixed minimum height/width (36px). The resizer between it and its sibling is hidden while collapsed.
toggleMaximize
Maximizes the panel so it covers the full LayoutRoot bounds. Only one panel can be maximized at a time — maximizing a second panel un-maximizes the first. Pass an explicit boolean to force a state; omit to toggle.
closePanel
Removes the entire panel from the layout tree. If the panel is the only child of its parent split, the split is also removed. No-op if this panel is the root node.
Usage in renderPanel
usePanel is most commonly called inside the renderPanel callback:
When to use useLayout instead
usePanel covers the vast majority of cases. Reach for useLayout when:
- Moving a tab between panels —
MOVE_TABinvolves two panels, so neither one "owns" the action.useLayoutgives youdispatchwithout being tied to a single panel id. - Reading the full tree — counting panels, walking the tree to find a panel by tab type, or rendering a layout overview.
- Replacing the entire layout —
REPLACE_LAYOUTswaps the whole tree at once. - Building UI outside
renderPanel— a top-level toolbar, breadcrumb trail, or workspace switcher that has no panel context to pass tousePanel.
The key difference is re-render scope: usePanel re-renders only when that specific panel changes. useLayout re-renders on any layout change anywhere in the tree. Use usePanel wherever it's sufficient.