Skip to content
WunderUI

useAppLayout

Pro

Opens the navigation drawer and the side panel of the surrounding AppLayout from your own buttons.

import { useAppLayout } from "@wunderui/react"

Playground

asideShown(): null

Wide frames show the panel in place; below 40rem it opens as a drawer over the page and starts closed.

Installation

useAppLayout comes with WunderUI Core and Pro, in the entry of the package from your plan. See the plans. Then import it:

tsx
import { useAppLayout } from "@wunderui/react"

When to use

Use useAppLayout for

  • A button inside the page that opens the details panel, such as a Details button in a table row.
  • A toggle for the aside that must read whether the panel is on screen, also in a narrow layout.
  • A custom menu button that opens the sidebar drawer, in a bar you built yourself.

Use something else for

  • AppLayoutNavigationTrigger for the ready-made menu button for the navbar. It hides itself above the drawer breakpoint.
  • AppLayoutAsideTrigger for the ready-made panel button with the pressed state and the label.
  • The `asideOpen` prop for an aside whose state you own, for example to keep it in the URL. The hook then only sets it.
  • Sheet for a drawer that has nothing to do with the app shell.

Signature

Returns the controls of the nearest : opens the sidebar as a drawer, shows or hides the right-hand panel, and says whether that panel is on screen right now. Outside an it returns .

ts
useAppLayout(): AppLayoutState | null

Returns

The controls of the nearest , or when the component is not inside one. The object changes when or the aside drawer changes, so a component that reads it re-renders then.

FieldTypeDescription
openNavigation() => voidOpens the sidebar as a drawer, whatever the width of the layout. It does nothing when the has no .
setAsideOpen(open: boolean) => voidOpens or closes the right-hand panel. In a layout narrower than the panel opens as a drawer. It calls too.
asideOpenbooleanThe open state of the aside. It is at the start, also in a narrow layout, where the panel is a drawer that begins closed.
asideShown() => booleanWhether the aside is on screen right now: the pane in a wide layout, an open drawer in a narrow one. It measures when you call it.
drawerBelow"40rem" | "48rem" | "64rem"The width of the layout below which sidebar and aside become drawers. The value of the prop.

Behavior and motion

The hook reads a context that `AppLayout` provides. It adds no listeners and no state of its own.

State
The aside starts open. In a layout narrower than that means the panel is a drawer that has not been opened yet, so is while is . then opens the drawer; closes it.
Measuring
compares the width of the layout, not of the window, with at the moment you call it. Read it in an event handler or an effect. A toggle is , not : in a narrow layout the second one would open nothing the first time.
Drawers
opens the sidebar drawer without checking the width; the navbar button hides itself above the breakpoint, your own button has to do that. The drawers are sheets that portal to the body, so they open over the whole page, move focus in, give it back to the button when they close, and close with Escape or the scrim. Without a or an prop there is no drawer to open.
Server rendering
The hook only reads a context, so it is safe to render on the server. reads and the layout's width; call it in handlers and effects only, never while rendering.
Cleanup
There is nothing to clean up. The removes its own observers when it unmounts.
Motion
The hook does not animate. Opening the aside moves its pane in (width and opacity, , ) and the drawers slide in as sheets.
Reduced motion
With the stylesheet takes width out of the transitions, so the pane appears at once, and the drawers lose their slide and keep the fade. The hook returns the same values either way.

Best practices

  • Do

    Check the result for before you use it, and disable or hide the control outside an .

  • Do

    Toggle with , so a narrow layout opens its drawer on the first press.

  • Don’t

    Do not call while rendering. It reads the DOM, and on the server there is none.

  • Do

    Pass to the . The aside is a landmark and an unnamed one loses its role.

  • Don’t

    Do not add your own menu button next to the navbar's . Two buttons open the same drawer.

  • Do

    Hide an button of your own above the breakpoint, as does, so there is not a drawer next to a visible sidebar.

Notes for AI

Give your coding assistant the page or the MCP call instead of screenshots.

MCPget_component("useAppLayout")
Importimport { useAppLayout } from "@wunderui/react"

The full library index for assistants is at /llms.txt.