useAppLayout
Opens the navigation drawer and the side panel of the surrounding AppLayout from your own buttons.
import { useAppLayout } from "@wunderui/react"Playground
Installation
useAppLayout comes with WunderUI Core and Pro, in the entry of the package from your plan. See the plans. Then import it:
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 .
useAppLayout(): AppLayoutState | nullReturns
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.
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.
get_component("useAppLayout")import { useAppLayout } from "@wunderui/react"The full library index for assistants is at /llms.txt.