All hooks and context consumers run on the client. The context hooks must be called inside DashboardLayout, which supplies the providers.
Context providers
DashboardLayout renders all three providers for you. You can also mount them directly if you build a custom shell. Each provider exposes a hook; the hook throws if used outside its provider (except useCommandPalette, which returns undefined so the topbar can degrade gracefully).
useSidebarContext()
Read and control the sidebar (desktop collapse + mobile off-canvas).
'use client'
import { useSidebarContext } from 'adminlte-react'
function CollapseButton() {
const { isCollapsed, toggle } = useSidebarContext()
return <button onClick={toggle}>{isCollapsed ? 'Expand' : 'Collapse'}</button>
}| Prop | Type | Default | Description |
|---|---|---|---|
isCollapsed | boolean | — | Desktop collapsed state. |
isMobileOpen | boolean | — | Mobile off-canvas open state. |
isMiniMode | boolean | — | Whether mini sidebar is enabled. |
toggle | () => void | — | Toggle collapse (desktop) or overlay (mobile). |
collapse | () => void | — | Collapse the sidebar. |
expand | () => void | — | Expand the sidebar. |
sidebarBreakpoint | number | — | Pixel width below which mobile behavior applies. |
useColorModeContext()
Read and set the color mode. Returns { colorMode, setColorMode, resolvedMode }. Covered in detail on the Theming & Dark Mode page.
useCommandPalette()
Open or close the ⌘K command palette programmatically.
'use client'
import { useCommandPalette } from 'adminlte-react'
function SearchButton() {
const palette = useCommandPalette() // may be undefined outside the provider
return <button onClick={() => palette?.open()}>Search</button>
}| Prop | Type | Default | Description |
|---|---|---|---|
isOpen | boolean | — | Whether the palette is open. |
open | () => void | — | Open it. |
close | () => void | — | Close it. |
toggle | () => void | — | Toggle it (also bound to ⌘K / Ctrl+K globally). |
Hooks
usePushMenu(options?)
Standalone sidebar state machine — the logic behind SidebarProvider. Use it when building a custom layout without the provider.
const { isCollapsed, isMobileOpen, toggle, collapse, expand } = usePushMenu({
sidebarBreakpoint: 992,
enablePersistence: true,
isMiniMode: false,
})| Prop | Type | Default | Description |
|---|---|---|---|
sidebarBreakpoint | number | 992 | Mobile breakpoint in px. |
enablePersistence | boolean | false | Persist collapsed state to localStorage. |
isMiniMode | boolean | false | Enable mini-sidebar behavior. |
useCardWidget(initialCollapsed?)
Collapse / maximize / remove state for a card. Powers the built-in Card tools; reuse it for custom card-like components.
const { isCollapsed, isMaximized, isRemoved, toggleCollapse, toggleMaximize, remove } =
useCardWidget(false)| Prop | Type | Default | Description |
|---|---|---|---|
isCollapsed / isMaximized / isRemoved | boolean | — | Current widget state. |
collapse / expand / toggleCollapse | () => void | — | Collapse controls. |
maximize / minimize / toggleMaximize | () => void | — | Maximize controls. |
remove | () => void | — | Mark the card removed. |
Argument: initialCollapsed (boolean, default false).
useDirectChat()
Toggle the contacts pane of a chat widget.
const { isContactsOpen, toggleContacts, openContacts, closeContacts } = useDirectChat()| Prop | Type | Default | Description |
|---|---|---|---|
isContactsOpen | boolean | — | Whether the contacts pane is open. |
toggleContacts / openContacts / closeContacts | () => void | — | Pane controls. |
useFullscreen()
Wraps the Fullscreen API. Powers the topbar fullscreen toggle.
const { isFullscreen, toggleFullscreen } = useFullscreen()
// enterFullscreen() / exitFullscreen() are also available (return Promise<void>)| Prop | Type | Default | Description |
|---|---|---|---|
isFullscreen | boolean | — | Current fullscreen state. |
toggleFullscreen | () => Promise<void> | — | Enter/exit fullscreen. |
enterFullscreen / exitFullscreen | () => Promise<void> | — | Explicit controls. |
useTreeviewAnimation(isOpen, speed?)
Animates a collapsible <ul> height. Returns a ref and inline style to spread onto the element. Powers the sidebar treeview.
const { ref, style } = useTreeviewAnimation(isOpen, 300)
<ul ref={ref} style={style} className="nav nav-treeview">…</ul>| Prop | Type | Default | Description |
|---|---|---|---|
isOpen | boolean | — | Open/closed state to animate toward. |
speed | number | 300 | Animation duration in ms. |
returns.ref | RefObject<HTMLUListElement> | — | Attach to the <ul>. |
returns.style | CSSProperties | — | Spread onto the <ul>. |
useSortable(enabled?)
Initializes drag-and-drop (via SortableJS, lazy-loaded) on every .connectedSortable element — shared group, dragged by .card-header. Install sortablejs. Great for Kanban boards and reorderable card columns.
'use client'
import { useSortable } from 'adminlte-react'
function Board() {
useSortable() // pass false to disable
return (
<div className="row">
<div className="col-md-4"><div className="connectedSortable">{/* cards */}</div></div>
<div className="col-md-4"><div className="connectedSortable">{/* cards */}</div></div>
</div>
)
}| Prop | Type | Default | Description |
|---|---|---|---|
enabled | boolean | true | Toggle initialization on/off. |