Skip to content

Hooks

All hooks must be called inside a <Window>’s children.

Returns a WindowHandle with stable imperative methods. References don’t change identity across renders.

function WindowContent() {
const win = useCurrentWindow();
win.focus();
win.close();
win.setBounds({ width: 800, height: 600 });
}

Read-only snapshots. The handle object identity changes when these change — don’t use the whole handle as an effect dependency.

FieldTypeDescription
idstringThe window ID
isReadybooleanfalse until the window is created and content mounted. Methods are no-ops until this is true.
isFocusedbooleanWindow has focus
isMaximizedbooleanWindow is maximized
isMinimizedbooleanWindow is minimized
isFullscreenbooleanWindow is fullscreen
boundsBoundsCurrent { x, y, width, height }

Method references are stable across renders — safe to pass as effect dependencies or event handlers.

MethodDescription
focus()Focus the window
blur()Unfocus the window
close()Close the window (respects closable)
forceClose()Force close (bypasses closable)
minimize()Minimize the window
maximize()Maximize the window
unmaximize()Restore from maximized
toggleMaximize()Toggle maximize state
setBounds(bounds)Set { x, y, width, height }
setTitle(title)Set the window title
enterFullscreen()Enter fullscreen mode
exitFullscreen()Exit fullscreen mode

Returns true if the component is rendering inside a <Window>’s children, false otherwise. Unlike the other hooks, this doesn’t throw when called outside a <Window> — use it to conditionally render components that call useCurrentWindow() and friends.

function StatusBar() {
const inside = useIsInsideWindow();
if (!inside) return <span>Main window</span>;
const focused = useWindowFocused(); // safe — we checked
return <span>{focused ? "Focused" : "Blurred"}</span>;
}

Each hook re-renders only when its specific value changes.

HookReturn TypeDescription
useWindowFocused()booleanWhether the window has focus
useWindowMaximized()booleanWhether the window is maximized
useWindowMinimized()booleanWhether the window is minimized
useWindowFullscreen()booleanWhether in fullscreen mode
useWindowVisible()booleanWhether the window is visible
useWindowBounds(){ x: number; y: number; width: number; height: number }Current bounds
useWindowDisplay()DisplayInfo | nullCurrent display — null until the window has moved at least once
useWindowState()WindowState | nullFull window state object — null before the window is ready
useWindowDocument()Document | nullThe child window’s Document (see Integration Notes)

DisplayInfo has the shape { id: number; bounds: Bounds; workArea: Bounds; scaleFactor: number }.

function WindowContent() {
const isFocused = useWindowFocused();
const isMaximized = useWindowMaximized();
const isMinimized = useWindowMinimized();
const isFullscreen = useWindowFullscreen();
const isVisible = useWindowVisible();
const bounds = useWindowBounds(); // { x, y, width, height }
const display = useWindowDisplay(); // { id, bounds, workArea, scaleFactor }
const state = useWindowState(); // full WindowState object
}

Use the specific hooks (useWindowFocused, useWindowBounds, etc.) rather than useWindowState when possible — they avoid unnecessary re-renders.

For manual bounds persistence. See Persistence for full usage.

const { bounds, save, clear } = usePersistedBounds("my-window", {
defaultWidth: 800,
defaultHeight: 600,
});
Return valueTypeDescription
bounds{ defaultWidth?, defaultHeight?, defaultX?, defaultY? }Saved bounds (mapped to default* prop names) or the defaults you passed. Spread directly into <Window>.
save(bounds: Bounds) => voidPersist current bounds. Debounced (default 500ms).
clear() => voidRemove saved bounds

The bounds keys are defaultWidth/defaultHeight/defaultX/defaultY — not width/height/x/y — so that {...bounds} spreads cleanly onto <Window> without accidentally creating a controlled window.