React Hooks for App Bridge
@launchmystore/app-bridge-react ships a typed hook for every App Bridge
action family. Each hook wraps the underlying SDK action class from
@launchmystore/app-bridge/actions, so the wire protocol stays exactly the
same — you just don’t have to construct messages by hand.
Installation
AppBridgeProvider
Mount once near the root of your iframe app:App instance, tears it down on unmount, and
hands it to every hook through a React context. Calling any hook outside
the provider throws useAppBridge must be used within an AppBridgeProvider.
Hook Index
Core
useAppBridge
Access the rawApp instance — useful when a built-in hook doesn’t cover
your case or you want to call app.dispatch(action, payload) directly.
Authentication
useSessionToken
Manages a cached JWT for authenticated backend calls. The hook fetches one token on mount and exposesgetToken() (returns the cached token unless
it’s near expiry, then refreshes) plus refresh() (forces a new token).
useAuthenticatedFetch, useAppQuery, useAppMutation
Helpers built on top ofuseSessionToken. useAuthenticatedFetch()
returns a wrapped fetch that injects the Bearer header automatically:
useAppQuery, useAppMutation).
UI Surface
useToast
Returns an object withshow, success, error, warning, info — not
a callable. Toast options accept { message, duration?, type? }.
The admin host reads
payload.type for the toast variant. The React
checkout host reads payload.variant. The useToast hook always sends
type — if you’re posting toasts from a checkout iframe, build the
payload manually with app.dispatch('TOAST_SHOW', { message, variant }).useModal
Opens a non-promise modal whose button callbacks fire as you set them.{ open(): void; close(): void }. Each open() call creates and
dispatches a fresh modal instance; close() dismisses the last one.
useConfirmationModal
Promise-returning variant — perfect for inlineawait.
useTitleBar
Configures the host’s title bar. Returnsupdate() (merges new options
into the live title bar) and setPrimaryLoading() for the common case of
showing a spinner on the primary button during async work.
useNavigationMenu
Declares the menu rendered by the admin chrome when your app is mounted. Provide an items array; the host renders them next to the page title.useContextualSaveBar / useDirtyState
useContextualSaveBar is the low-level hook — call show() / hide() /
update() / setSaveLoading() / setDiscardLoading() directly.
useDirtyState glues that together with an internal dirty flag:
useLoading
Drives the host’s global thin-progress-bar via theLOADING_START /
LOADING_STOP actions. Use wrap() for the common pattern.
{ start, stop, wrap<T>(fn: () => Promise<T>): Promise<T> }.
useFullscreen
isFullscreen flips to true when the host posts back
FULLSCREEN_ENTERED (similarly false on FULLSCREEN_EXITED), so you
can mirror the host’s actual state instead of guessing.
useLeaveConfirmation / useUnsavedChanges
useLeaveConfirmation exposes manual enable() / disable() /
setMessage(). useUnsavedChanges wraps it with a setDirty(boolean)
helper that enables/disables in lock-step with form state.
beforeunload event under the
hood, so closing the tab triggers the same confirmation.
Resource Picker
useResourcePicker
Generic resource picker — passresourceType plus optional multiple,
initialSelectionIds, filter, onSelect, onCancel.
{ open(): void; close(): void }.
Typed convenience hooks
useResourcePicker minus resourceType.
There is no
useOrderPicker / useArticlePicker / useMenuPicker. For
those, call the generic useResourcePicker({ resourceType: 'order' }).
The full type list lives in Actions
Reference.Navigation
useRedirect
Returns a menu of typed navigation helpers — the genericnavigate()
plus open() (new tab) and one helper per Admin resource detail page.
Browser APIs
useClipboard
copy() writes through the browser’s navigator.clipboard.writeText API.
paste() round-trips to the host (CLIPBOARD_READ_REQUEST) — required
because Chrome blocks clipboard.readText() in cross-origin iframes.
useCopyToClipboard() is the slim variant — just (text) => Promise<void>.
usePrint
usePrint() returns a single function: print() => void. The host opens
the browser print dialog scoped to your iframe.
useShare
Wraps the Web Share API (mobile).useShare() returns
{ share: (data: { title, url, text? }) => Promise<void>; isSupported }.
useHistory
Drives the host browser history —push, replace, go, back,
forward. Useful when your app uses its own router and you want
host-aware history.
Lifecycle
useLifecycle({ onFocus, onBlur, onVisible, onHidden }) plus the four
single-event variants useOnFocus, useOnBlur, useOnVisible,
useOnHidden. Fired when the host detects the iframe has focused,
blurred, become visible, or been hidden.
Data APIs
All four are RPCs the first time you call them and cache the result;
refresh() forces a round-trip.
Subscriptions
Three escape hatches when no typed hook exists for what you need:useAppSubscription(action, callback)— subscribe to a host-initiated action (e.g.MODAL_PRIMARY_ACTION). Returns nothing; cleanup happens on unmount.useAppDispatch()— returns the bound(action, payload?) => stringfunction from the underlying App.useAppDispatchAndWait()— returns the bound(action, payload?) => Promise<payload>function.
Checkout
useCart
Returns a memoisedCart action instance for the checkout host. Use it
inside checkout extensions to mutate the host cart:
applyDiscountCodeChange, applyNoteChange,
applyAttributeChange, applyGiftCardChange, etc.).
Complete Example
A realistic admin block that combines auth, save bar, resource picker, title bar, and the loading indicator:TypeScript
Every hook ships with typed return values, options, and accompanying types —UseToastReturn, UseModalOptions, UseResourcePickerReturn,
UseSessionTokenReturn, etc. Import from the package root.
useI18n
Subscribes to host-driven locale changes and exposes translate,
formatNumber, formatDate helpers (backed by Intl.*).
I18N_UPDATE, so
locale changes from the admin chrome propagate without manual handling.
useRestApi
Returns authenticated fetch / fetchJson helpers for the LaunchMyStore
REST API. Session token and API base URL are resolved lazily and
cached.
/api/v1/...
paths. The hook handles Authorization: Bearer <token> and resolves the
base URL from CONFIG_GET so your iframe works in dev, staging, and
production.
useIntents
Launches another app’s admin action by intent target.
useApi — the umbrella hook
For pages that need most of the App Bridge surface, useApi() returns a
single object containing every helper:
See Also
- React Components —
<TitleBar />,<NavigationMenu />,<AdminBlock>,<AdminAction>, layout/text/form primitives and design tokens. - Actions Reference — payload shapes for every action.
- Sessions & Authentication — token verification on your backend.
- App Bridge for Checkout —
useCartpayload reference. - App Bridge Overview — raw SDK if you don’t want React.