Axonpack

Reference

Every export, config field, hook result, label and theme token.

Use this page to look up a name. If you are new, start with the Quick start. Every command of the CLI is on CLI.

Components and hooks

ExportWhat it is
PreviewProvider{ config: PreviewConfig, children }. Mount it near the root, on every start
PreviewListThe ready-made list. Props below
usePreview()The list and its actions. Needs the provider above it
usePreviewStatus(labels?)What runs now and the build it runs in. See below. Needs the provider
useRunning()What this start runs, as a Running. Needs the provider
usePreviewFiles(name)Which copy of a file set goes with the running bundle, as PreviewFiles. Needs the provider
usePreviewsState()The raw store state, without the provider
useDevPreviewServersState(){ servers, activeUrl, alive, error, scanning, hosts } for dev preview servers. alive is every host:port that answered the last look, or null before one

PreviewList props

PreviewList is a FlatList, and takes FlatList's props as well as its own, unless virtualized is false.

PropWhat it is
themeNothing, a partial theme or an expo-devtools palette. See Theme
labelsAny text. See Labels
styleThe FlatList's style, over the list's background colour
contentContainerStyleOver the list's padding: 16 all round and 112 at the end, which clears a floating tab bar. Set paddingBottom to fit your own
ListHeaderComponentYour own element above the list's header (the error banner and the header card)
ListFooterComponentYour own element after the last row
virtualizedDefault true. false draws every row at once in a plain ScrollView, for a place a FlatList can't run, such as a React Native DevTools tab. There is no pull to refresh then, and of the FlatList props only style, contentContainerStyle and ListHeaderComponent are used
Any other FlatList propPassed through, such as onScroll, testID or showsVerticalScrollIndicator

For Add a host's field, the list sets keyboardShouldPersistTaps="handled" and, for iOS, automaticallyAdjustKeyboardInsets. Pass your own to change them.

The list keeps these for itself, so they can't be passed: data, getItem, getItemCount, renderItem, keyExtractor, ItemSeparatorComponent, CellRendererComponent, getItemLayout, numColumns, columnWrapperStyle, horizontal, refreshing, onRefresh, refreshControl (pull to refresh is built in, coloured from the theme) and ListEmptyComponent (the list always has its section headings, and says itself when nothing is published).

PreviewConfig

What the app passes to the provider. Nothing here is read from the environment.

FieldNeededWhat it is
enabledYestrue turns previews on. You decide per build; nothing is detected
s3ConfigNoThe bucket and how to read it (PreviewS3Config, below). Without it, the list shows previews as not set up
devPreviewServersNoLists this app's Metro servers in a debug build, while enabled is true. true, or an object (below). Default off. See Dev preview servers
buildKeyNoThis build's key, only when the config plugin is not used to bake it in
slugNoThe app's Expo slug, only when the config plugin is not used to bake it in. Previews are read from the bucket folder named after it
filesNoThe app's own copy of each file set, by the name the config plugin's files option gives it (PreviewFilesOptions, below). See Files with a preview

s3Config (PreviewS3Config):

FieldNeededWhat it is
urlYesWith a read key: <endpoint>/<bucket>, the same as PREVIEW_S3_URL. Without one: any address the files are public under, such as that URL, https://pub-<id>.r2.dev or a CDN. The app reads from the folder named after its slug under it. Left out or empty at runtime, the list shows previews as not set up
readAccessKeyIdNoA read-only key, for a private bucket. Never the write key
readSecretAccessKeyNoIts secret
regionNoSigning region for a private bucket. Default us-east-1; auto on R2
headersNoExtra headers on every read, for a proxy, CDN or tunnel in front of the bucket
s3Config: {
  url: process.env.EXPO_PUBLIC_PREVIEW_S3_URL as string,
  readAccessKeyId: process.env.EXPO_PUBLIC_PREVIEW_S3_READ_ACCESS_KEY_ID,
  readSecretAccessKey: process.env.EXPO_PUBLIC_PREVIEW_S3_READ_SECRET_ACCESS_KEY,
  region: process.env.EXPO_PUBLIC_PREVIEW_S3_REGION,
},

url is typed as a string, and an env value can be undefined, so pass it with as string. Left out or empty at runtime, the list shows previews as not set up: the app reads nothing from a bucket and shows no error, and dev preview servers and the header card work as usual. A url that is set but is not a full address, such as /previews, is still an error.

0.1.0 took these five fields at the top level of the config. They still work but are deprecated, and the old top-level url follows the same rule. When s3Config is set too, it wins, and the app logs one warning.

devPreviewServers as an object (DevPreviewServersOptions). true is the same as {}.

FieldDefaultWhat it is
enabledtrueTurns the section on
allowCustomHoststrueShows Add a host, so QA can add another computer on the device
hostsnoneOther computers the app asks, such as "192.168.1.24" or "qa-mac.local:19150". The port is the registry's, 19150 when left out. An entry that is not a host, is listed twice, or is this computer is skipped with a console.warn

localhost, 127.0.0.1, and 10.0.2.2 on Android are always checked and need no entry.

Each entry of files (PreviewFilesOptions):

FieldNeededWhat it is
defaultYesThe folder of the app's own copy, as a file:// URI, such as file:///android_asset/www/
onPostDownloadNo(name, uri, { previousUri }) => void | Promise<void>. Runs once each time a preview's copy finishes downloading, with the folder it stays in and previousUri undefined. The download is done when it returns. On iOS it runs again on the first start after an app update moved the folder, for the running preview, with the old folder as previousUri. If it throws, the download is deleted. See After an app update
files: {
  www: {
    default: 'file:///android_asset/www/',
    onPostDownload: (name, uri, { previousUri }) => rewritePaths(uri, previousUri),
  },
},
devPreviewServers: {
  allowCustomHosts: true,
  hosts: ["192.168.1.24", "qa-mac.local:19150"],
},

usePreview

FieldWhat it is
enabledconfig.enabled
previewsConfiguredA bucket URL is set. False when s3Config.url is undefined, empty or blank
devPreviewServersWhether dev preview servers are on: enabled and devPreviewServers both
itemsPreviewItem[]: this build's previews, and downloads it no longer lists
incompatibleDownloads made for another native build
loadingA refresh is running
errorThe last error, as text, or null
buildKeyThis build's key, or null without the plugin
remoteWhat the bucket lists for this build. Null until it has answered once
localEvery download on the device
downloadingDownload progress by id, from 0 to 1
activeIdThe preview the next start loads, or null for the default bundle
runningIdThe preview that runs now, or null. Not activeId when the chosen one did not load
brokenIds of previews that stopped before they finished starting, until they are downloaded again or switched to
ActionWhat it does
refresh()Reads the downloads, then asks the bucket for this build's list. With no bucket URL it asks nothing
download(id)Downloads a preview, or its update, and takes it off broken
switchTo(id)Restarts into a preview, downloading it first if needed. Also stops a dev preview server
switchTo(null)Back to the default bundle. Also stops a dev preview server
remove(id)Deletes a download. If it runs, goes back to the default bundle first
removeIncompatible()Deletes every download made for another native build

PreviewItem

FieldWhat it is
idThe preview's id
entryThe bucket's entry: title, branch, commit, author, publishedAt, appVersion, buildNumber, compatibility, fingerprint, environment (only when published with --environment), fileSets (only when published with file sets: { [name]: { files, size } }), size, changelog, revision, manifest
statusavailable, downloading, downloaded, update-available, unpublished or broken
progress0 to 1 while downloading, else null
activeIt runs now: what native started from, not only what was chosen
localThe download on the device, or null

Running

kindFields
defaultsource (built-in, expo-dev-server or dev-preview-server), url, hostPort, server
previewid, title
localurl, hostPort, server (null until the list has found it)

0.1.0 called the default bundle kind: 'base', with no other fields. It is kind: 'default' now. A picked server that is the Metro the app starts on anyway counts as the default.

usePreviewStatus

Everything the list's header card shows, for a banner, badge or debug screen of your own. Pass the list's labels to name the kinds the same way. Its type is PreviewStatusInfo.

FieldWhat it is
runningWhat runs now, as useRunning() returns it
kinddefault, preview or local (a server picked in the list)
bundleKindWhere it comes from: built-in, expo-dev-server, dev-preview-server, preview, or server for a server no look has found, whose kind is not known. Picks the header card's chip
titleThe header card's title: the preview's title, a preview start server's title, Default for the Metro the app starts on, another server's address, or the kind's name
idThe running preview's id, or null
branchThe running preview's or server's branch, or null
addressA server's host:port, with loopback shown as localhost, or null
labelOne sentence for what runs, such as "Expo server, localhost:8081"
isDefaultThe default bundle runs: nothing picked, or what was picked is what the app starts on anyway
onlineWhether the server the app runs from answers: false once a look for dev preview servers did not find it. Null for a preview or a bundle built into the app, before the first look, and with dev preview servers off
scanningA full scan of every port for dev preview servers runs now: on open, on refresh, and every 30 seconds. The quick look every 2 seconds does not count
hostsWhere the app looks for dev preview servers: { host, port, source }, where source is built-in, app (from the config) or user (added on the device). Empty until the first look
environmentThe running preview's EAS environment, or null
authorThe running preview's author, or null
commitThe running preview's full commit, or null
publishedAtThe running preview's ISO publish date, or null
app{ name, version, buildNumber, platform } of this build. Nulls on a native side older than the JS
compatibility{ mode, key }: appVersion or fingerprint, and the build key
filesWhich copy of each file set in the config's files is in use, by name, as PreviewFiles. Empty without files
previewsConfiguredA bucket URL is set. False when s3Config.url is undefined, empty or blank, and then nothing is read from a bucket
loadingThe previews list is loading
errorThe last error, as text, or null
canGoBackA preview is chosen (even one that could not load) or a server is picked (even one that did not answer)
ActionWhat it does
backToDefault()Restarts on the default bundle, clearing the chosen preview and the picked server
refresh()Asks the bucket again, and scans every port for dev preview servers when they are on

Functions

FunctionWhat it does
selectPreview(id, key?)Chooses what the next start or reload() loads: a preview id, or null for the default bundle. False where the native module is missing
reload()Restarts JS, so a new choice takes effect. False where the native module is missing
previewBundlePath(id)Where a preview's bundle sits, relative to the preview folder
previewFilesPath(name, config)usePreviewFiles(name) outside React, with the config passed in. Throws for a name config.files doesn't list
markLaunched()Tells the native side this start worked. The provider calls it
buildKey()The key the plugin baked into this build, or null
buildCompatibility()appVersion or fingerprint, as baked in, or null
buildSlug()The app's slug, as baked in, or null. It names the app's folder in the bucket
previewTitle(id)The readable title for an id: task-1-login-fix becomes "Task 1 login fix"
previewItems(state){ items, incompatible } from the store state
runningNow(input)The pure form of useRunning()
runningLabel(running, labels)One sentence for what runs, as usePreviewStatus().label
runningKind(running, labels)The kind's name, such as "Expo server" or "Preview"
sameServer(a, b)Whether two host:port values are one server: the same port, and the same host or two names for this computer (localhost, 127.0.0.1, 10.0.2.2)
resolveTheme(theme, scheme)A full list theme from the theme prop and the device's colour scheme
fromDevtoolsPalette(palette)The list theme keys an expo-devtools palette maps to

Types: PreviewConfig, PreviewS3Config, PreviewFilesOptions, PreviewFiles, PreviewsState, PreviewItem, PreviewStatus, Running, DefaultSource, BundleKind, PreviewStatusInfo, PreviewListProps, PreviewListTheme, PreviewListThemeInput, PreviewListFonts, DevtoolsPaletteLike, PreviewListLabels, DevPreviewServersState, DevPreviewServer, DevPreviewServersOptions, DevServerHost and HostAddress.

previewsStore and devPreviewServersStore are the stores behind the hooks, with getState() and subscribe(), for use outside React. devPreviewServersStore.addHost({ host, port }) and removeHost({ host, port }) add and remove a host on the device, as the list does. The server the app runs from, or the one picked in the list, has unknown: true when no look has found it answering and nothing was saved about it, so its kind and name are not known. previewsStore.clearError() hides the error, as the snackbar's Dismiss does.

PreviewFiles

What usePreviewFiles(name) and previewFilesPath(name, config) return.

FieldWhat it is
uriThe copy's folder, as a file:// URI that always ends in /
sourcepreview when the running preview was published with the set, else default
previewIdThe preview whose copy it is, or null for the default copy
readyFalse while the preview's copy waits for its onPostDownload on start, and for the rest of the start once that onPostDownload threw. Always true for the default copy and for a set without onPostDownload. The hook renders again when it changes; previewFilesPath returns what is true when it is called

Theme

PreviewList's theme takes one of three things:

  • Nothing. LIGHT_THEME or DARK_THEME, following the device. Only these two are built in.
  • A partial PreviewListTheme. Any keys below. The rest come from light or dark, picked by mode.
  • An expo-devtools palette (DevtoolsPaletteLike, the shape of its Palette), told apart by its textPrimary and accent keys. fromDevtoolsPalette maps it: surface to card, sectionTint to surface and tint, textPrimary to title and text, textSecondary to muted, accent to primary, error and errorSurface to danger and dangerSurface, and codeKeyword, jsonNumber and jsonString to info, accent2 and accent3. mode comes from how dark its background is, and primaryText is white or black, whichever reads on accent.

A chip's text is its tone on a light wash of it; where the tone would be hard to read on the card or the header card's tint, its text is darkened (or lightened, on a dark theme) just enough. A tone that is not a hex colour gets an outline instead of a wash.

KeyLightDarkWhat it colours
modeautoautoauto (follows the device), light or dark
background#f4f6fa#12151fBehind the list
card#ffffff#1c2130Each card
surface#eef1f6#262c3dBehind the changelog and the progress track, and a pressed row
tint#e6eefc#1f2b47The header card, and the row the app runs from
tintBorder#c9d6ef#3a4560The header card's border, which border would lose on the tint
border#e4e8f0#323a4fCard, button and divider lines
title#0f172a#f8fafcHeadings, and the error snackbar's message
text#334155#cbd5e1Body text
muted#56637a#94a3b8Quiet text: hints, who published and when, size, and plain chips
primary#2563eb#5b8defMain buttons, Show details, the Preview chip and Downloading
primaryText#ffffff#0b1220Text on main buttons
danger#dc2626#f87171Delete, the error snackbar's edge, Offline, Unpublished and Broken
dangerSurface#fff6f6#3b1d1dBehind the error snackbar
warning#d97706#fbbf24Update available, Made for another native build, and the Metro note
success#16a34a#4ade80Active and Downloaded
info#0e7490#22d3eeThe server: Expo chip and the branch line
accent2#7c3aed#a78bfaThe server: Preview chip
accent3#be185d#f472b6The env: chip
radius1414Card corner radius. Buttons scale from it
fonts{}{}{ regular, medium, bold } font family names. Each falls back to the system font

Labels

PreviewList's labels takes any of these. DEFAULT_LABELS has the defaults. A name in braces, such as {host}, is filled in. status, statusShort and timeAgo are merged per key, so labels={{ statusShort: { broken: 'Crashed' } }} changes only that one.

Header card

LabelDefaultWhere it shows
runningRunningWhat a screen reader says before what runs
defaultServerChipDefault serverThe chip on the Metro the app starts on: on its row, and in the card while it runs
defaultBundleDefault bundleThe chip in the card while the bundle built into the app runs, as in a release build
kindBuiltInBuilt into the appThe title for a bundle built into the app
kindExpoDevServerExpo serverWhat a screen reader says for the server: Expo chip
kindDevPreviewServerPreview serverWhat a screen reader says for the server: Preview chip
kindPreviewPreviewThe chip for a running preview
kindServerServerThe chip, with no hue, for a server no look has found and nothing was saved about
offlineOfflineThe chip on the card and on the row of the server the app runs from, once it stops answering, and on the row of a picked server the app started without
offlineHintStart this server again, or go back to default.Under the chips when a picked server stops answering
offlineDefaultHintStart Metro again, then reload.Under the chips when the Metro the app starts on stops answering
serverPrefixserver:Before a server's kind on its chip
serverExpoExpoA plain Expo server's kind on its chip
serverPreviewPreviewA preview start server's kind on its chip
refreshRefreshWhat a screen reader says for the Refresh icon
showDetailsShow detailsOpens the rest of the facts
hideDetailsHide detailsCloses them
authorAuthorFact name
publishedPublishedFact name
branchBranchFact name, and what a screen reader says before a branch
previewIdPreview idFact name
environmentEnvironmentFact name, and what a screen reader says for the env: chip
appAppFact name
versionVersionFact name
commitCommitFact name
platformPlatformFact name
compatibilityMatched byFact name
compatibilityAppVersionApp versionIts value in appVersion mode
compatibilityFingerprintFingerprintIts value in fingerprint mode
compatibilityKeyBuild keyFact name
filesFilesBefore each file set's name in the details, as in "Files: www"
filesPreviewPreview's copyIts value when the running preview's copy is in use
filesDefaultDefault copyIts value when the app's own copy is in use
backToDefaultBack to defaultThe card's action: back to the default Metro in a debug build, to the bundle built into the app in a release build
metroBypassedDebug build: Metro is not used while a preview runs. Back to default loads from Metro again.Under the facts while a preview runs in a debug build

Error snackbar

Text between backticks shows in a code font.

LabelDefaultWhere it shows
errorUnreachableCan't reach the bucket at {host}.The bucket did not answer
errorEmulatorHintOn the Android emulator, use `10.0.2.2`, or run `adb reverse tcp:{port} tcp:{port}`.Under it, on Android when the bucket is on localhost
errorForbiddenThe bucket refused access.A 403
errorForbiddenHintCheck the read key or the bucket's policy.Under it. None when you set errorForbidden and not this
errorNotFoundThe bucket or the file was not found.A 404
errorNotFoundHintCheck the bucket URL in the preview config.Under it. None when you set errorNotFound and not this
errorGenericSomething went wrong.Anything else. The raw error goes under it
retryRetryDoes again what was tapped last
dismissDismissHides the snackbar

Dev preview servers

LabelDefaultWhere it shows
devPreviewServersTitleDev preview serversThe section's heading
devPreviewServersHintMetro servers for this app on these hosts.Under the heading
scanningScanning…What a screen reader says for the spinner after the heading's title, during a full scan of the ports
hostsHostsThe row at the end of the servers card, with a count. Opens the list of hosts
addHostAdd a hostThe last row of the servers card. Opens the field in its place
addHostPlaceholder192.168.1.24 or qa-mac.localIn the empty field
addHostHintA computer running npx preview start. Add :port if its registry is not on 19150.Under the field
clearHostClearWhat a screen reader says for the field's clear button
addHostConfirmAddAdds what is in the field
cancelCancelCloses the field
removeHostRemove {host}What a screen reader says for a host's ✕
hostInvalidThat is not an IP address or a host name.Under the field, in place of the hint
hostDuplicate{host} is already in the list.Under the field
hostBuiltIn{host} is always checked.Under the field, for localhost and this computer's other names
activeActiveThe chip on the server or preview the app runs from
defaultServerTitleDefaultThe title of the Metro the app starts on, when preview start gave it none
switchToServerSwitch to {title}, {address}What a screen reader says for a server row
switchToServerHintRestarts the app on this server.Its hint
localIncompatibleMade for another native buildA server's chip
localUnknownBuildNative build unknownA server's chip
noDevPreviewServersNo Metro server found. Start one with npx preview start.When none is found
noBuildSlugThis build has no app slug, so it cannot tell its servers from other apps'. Add the config plugin and rebuild.Instead of the servers, in a build without the plugin

Published previews

LabelDefaultWhere it shows
previewsTitlePublished previewsThe section's heading
previewsNotConfiguredPreviews aren't set upUnder the heading when the config has no s3Config.url
previewsNotConfiguredHintAdd s3Config.url to the preview config to list published previews.Under previewsNotConfigured
emptyNo previews published for this build yet.When none is published
noBuildKeyThis build has no compatibility key, so it cannot list previews. Add the config plugin and rebuild.In a build without the plugin
branchPrefixBranch:Before the branch name on a row
statusPrefixstatus:Before the status on its chip, which starts the status in lower case
statusNameStatusWhat a screen reader says before the status
statusShortOne per status: Not downloaded, Downloading, Downloaded, Update available, Unpublished, BrokenThe status on its chip
brokenHintIt stopped while starting, so the default bundle loaded instead.Under the chips of a broken preview
environmentPrefixenv:Before the environment name on its chip
byline{author}, {time}Who published it and when
filesFilesBefore a preview's file sets and their sizes, as in "Files: www 2.1 MB"
timeAgonow Just now, minute 1 minute ago, minutes {n} minutes ago, hour 1 hour ago, hours {n} hours ago, day 1 day ago, days {n} days agoHow long ago. Older than 30 days shows the date
showMoreShow moreOpens a long changelog
showLessShow lessCloses it
downloadDownloadAction
switchToSwitchAction
updateUpdateAction
deleteDeleteAction

Incompatible

LabelDefaultWhere it shows
incompatibleTitleIncompatibleThe section's heading
incompatibleHintMade for another native build, so they can't run here.Under the heading
deleteAllDelete allThe section's action

Deprecated

Still accepted, so an app written for 0.1.0 type-checks.

LabelDefaultNow
titlePreviewsNot shown. The list opens with the header card
baseBaseNot shown. The card names the default by what serves it
backToBaseBack to defaultUse backToDefault. Still shown when backToDefault is not set
stopDevPreviewServerStop using dev preview serverNot shown. Back to default stops a picked server
localSuffixlocalNot shown. The chip names the server's kind
statusOne per status, as statusShort, with Broken: it stopped while startingUse statusShort. Still shown for any status statusShort does not set

Config plugin

["@axonpack/preview", { "compatibility": "appVersion" }]
OptionDefaultValues
compatibilityappVersionappVersion or fingerprint
filesnoneFile sets to publish with each preview: a name and a folder from the app's root, such as { "www": "web/dist" }, or a name and { "folder": "web/dist", "build": "<command>" }, whose command preview publish runs first, from the app's folder in its copy of the project (the app's root with --in-place) and with the --environment values. Read by preview publish only

preview publish stops with an error that names the option when files is not an object of names and folders, when a name has a character other than letters, digits, ., _ and - or starts with a dot, or when a set is neither a folder nor an object with a folder, as text that isn't empty. A build, when given, must be text that isn't empty too.

See Compatibility for what it writes into the build, and Files with a preview for files.

On this page