Overview
useApp creates an App instance, connects it to the host via PostMessageTransport, and returns the connection state. Options are only used on the initial mount — the hook does not reconnect when options change.
Signature
UseAppOptions
App identification sent to the host during
ui/initialize.Features this app provides (e.g.,
{ tools: { listChanged: true } }).Called after
App is created but before connect(). Use this to register event handlers that must be in place before the initialization handshake.AppState
The connected
App instance, or null during initialization.Whether initialization completed successfully.
Connection error if initialization failed,
null otherwise.Usage
Behavior
- HMR persistence — The
Appinstance persists across React Fast Refresh, so code changes don’t trigger reconnection. A full page reload establishes a fresh connection. - Strict Mode — The
Appis intentionally not closed on unmount to avoid cleanup issues during React Strict Mode’s double-mount cycle. Callapp.close()manually if needed. - Auto-resize — The
Appis created withautoResize: trueby default. For custom options, create theAppmanually and useuseAutoResize. - Options stability — Options are only read on initial mount. Changing
appInfo,capabilities, oronAppCreatedafter mount has no effect.