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. It is safe under React
StrictMode (the development double mount does not tear the instance down).
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. show() takes the full Toast options:
{ message, duration?, type?, isError?, action?: { label, onAction } }.
The admin and checkout hosts both read the toast variant from
type,
variant or Shopify’s isError, so the hook works unchanged in either.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.
disabled, loading (spinner, button disabled) and
destructive (critical style). Breadcrumbs accept url / destination and
an optional onAction; a click runs onAction, otherwise /admin/... paths
and absolute URLs navigate the admin and other paths open that page of your
app. The hook always calls your latest callbacks and only re-sends the bar
when what it shows changes. update() / setPrimaryLoading() changes hold
until the options you pass to the hook change.
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 — and inside an
admin action the admin asks before the merchant
closes the action modal. The hook keeps one confirmation for the component’s
lifetime (re-renders don’t reset it), applies message changes, and disables
it on unmount.
Resource Picker
useResourcePicker
Generic resource picker — passresourceType plus optional multiple,
selectionIds (legacy alias initialSelectionIds), filter,
selectionFormat, onSelect, onCancel, onError.
{ open(): void; close(): void }. onSelect always receives an
array (one item for single-select). The item fields per resource type are
listed under Selection items; pass
selectionFormat: 'handle' for the old handle strings. onError fires when
the admin cannot open the picker (for example metaobject, which is not
available yet), followed by onCancel.
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 the 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.
toProduct / toCollection / toOrder / toCustomer open that resource’s
admin page — pass the admin’s resource id (useApi().data.productId, a picker
selection’s id; for products and collections the numeric id works too). toApp(path) opens a page of your
app inside the admin; toAdmin(path) opens an admin path ('' for the
dashboard, /orders, /products/<id> …); navigate() accepts documented
/admin/... paths. See Redirect.
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. It opens the
browser print dialog for your iframe’s own page.
useShare
Wraps the Web Share API.useShare() returns
{ share, isAvailable, canShareFiles, canShare, sharing, error } —
share(data) performs the share (through the admin when your iframe can’t
share by itself), sharing is the in-flight flag, and
canShare(data) / canShareFiles probe capability. share() resolves when
the merchant shares or dismisses the sheet, and rejects (setting error)
when the browser can’t share.
useHistory
push, replace, go, back, forward on your iframe’s own history —
the browser’s back button follows it. The admin only acknowledges these; it
does not change the admin’s URL (use useRedirect().toApp() for that). path
and state are read at render time.
Lifecycle
useLifecycle({ onFocus, onBlur, onVisible, onHidden }) plus the four
single-event variants useOnFocus, useOnBlur, useOnVisible,
useOnHidden. They fire when your iframe gains or loses focus or visibility,
and when the admin tab does (the admin pushes APP_FOCUS / APP_BLUR /
APP_VISIBLE / APP_HIDDEN); each change fires once.
Data APIs
useUser / useConfig / useEnvironment are RPCs the first time you
call them and cache the result; refetch() (not refresh) forces a
round-trip. useFeatures never round-trips — it reads the SDK’s local
capability table.
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,APP_VISIBLE). The callback gets(payload, error). Returns nothing; cleanup happens on unmount.useAppDispatch()— returns the bound(action, payload?) => stringfunction from the underlying App.useAppDispatchAndWait()— returns the bound(action, payload?, options?) => Promise<payload>function (options.timeoutas indispatchAndWait).
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.
translate(key, vars) takes a plain interpolation map;
translate(key, { default, vars }) adds a fallback string. The admin sends
the merchant’s language but no dictionary, so translate returns your
default (or the key) with {{vars}} filled in — keep your own strings
keyed by locale. See I18n.
useRestApi
Authenticated requests to your app’s own backend (the
authenticatedFetch model): every call carries
Authorization: Bearer <session token>, which your backend verifies with
your client secret. Relative paths resolve against your app’s origin;
absolute URLs are used as-is. The token is cached until shortly before it
expires and refreshed once on a 401.
The returned object is stable across renders, so it is safe in effect
dependency lists.
useIntents
Opens another installed extension’s admin action (or block) by its target.
Address it with the manifest target — admin.order-details.action.render
opens the extension registered there, and
admin.order-details.action.<handle> the one with that handle.
launchAndWait resolves with { launched: true, target } once the admin
has opened the extension and rejects when no installed extension matches
the target. launch(target, payload?) is the fire-and-forget form. The
launched extension reads payload from its context as
useApi().data.intent.payload.
useApi — the umbrella hook
For pages that need most of the App Bridge surface, useApi() returns a
single object containing every helper:
This is the recommended entry point for admin block / admin action
React components — one shared API surface, automatic listener cleanup,
and stable references across renders.
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.