Some values belong in the app config and also in the running app: a support address, a limit the UI enforces, a feature switch. Expo ships most of the resolved config with the app and exposes it through the expo-constants package, while a few fields are deliberately stripped. Knowing which is which tells you where your own values go and what must never be put there.
Key terms
- extra: an app config object for any fields of your own that you want to pass to the app.
- Constants.expoConfig: the property of
expo-constants' default export that holds the app config at runtime. - public app config: the config that builds and updates embed, with a short list of fields filtered out.
Put your own values in extra
Values of your own go under extra, an optional object that takes any keys. Expo passes it to the app with the rest of the config. The first example below adds supportEmail and maxSavedTrails to Trailmix's app.config.ts, after the usual ...config spread.
The same object works in app.json, inside expo. Use app.config.ts when the value is computed.
Constants.expoConfig in a component
Constants is the default export of expo-constants, which the default template already lists as a dependency. Constants.expoConfig contains most of the app config, and your values sit under Constants.expoConfig.extra.
Constants holds more than the app config. The device and the operating system provide some of its values, such as Constants.deviceName and Constants.systemFonts. expoConfig is the part that comes from your app.json or app.config.ts, whether the manifest is embedded in the build or served remotely by the dev server.
The second example, a SupportFooter component, reads the address with
tsxconst supportEmail: string | undefined = Constants.expoConfig?.extra?.supportEmail;
Both question marks are needed. expoConfig is typed as ExpoConfig plus an optional hostUri, or null, and the getter returns null when no manifest is available. extra is optional in ExpoConfig. The docs' example is plain JavaScript (App.js) and writes Constants.expoConfig.extra.fact without optional chaining. The same line in a .ts or .tsx file fails type checking under the template's tsconfig.json, which sets "strict": true, because expoConfig can be null. The values in extra are typed any, so the annotation on supportEmail is what gives you type checking afterward.
hostUri is only present during development with Expo CLI. Constants.manifest is deprecated: use Constants.expoConfig instead.
Don't import app.json or app.config.ts into app code to get the same values. That imports the whole file rather than the processed config, so you get the file as written instead of what Expo resolved from it.
Fields that stay out of the app
Because most of the config is readable at runtime, it is no place for sensitive information, with one exception. Four fields are filtered out of the public app config and are not available on Constants.expoConfig:
ios.config, which holds keys such asgoogleMapsApiKeyandroid.config, which holds keys such asgoogleMaps.apiKeyupdates.codeSigningCertificate, the local path to the certificate that verifies signed updatesupdates.codeSigningMetadata
ios.config and android.config hold API keys and are used only in the build process. Everything else stays, name, version and all of extra included. A value under extra is as visible as the app name.
To see exactly what will be embedded in your builds and updates, and so readable at runtime, run npx expo config --type public. Builds embed this public config, and npx expo export builds its manifest from it.
During npx expo start, though, the dev server builds its manifest from the full config without the public filter, and Constants.expoConfig returns that manifest's config. Logging Constants.expoConfig.ios in development can show ios.config even though a build won't have it. To know what the app will see, check --type public.
Code Examples
import { ConfigContext, ExpoConfig } from 'expo/config';
export default ({ config }: ConfigContext): ExpoConfig => ({
...config,
name: 'Trailmix',
slug: 'trailmix',
extra: {
supportEmail: 'help@trailmix.example',
maxSavedTrails: 50,
},
});import Constants from 'expo-constants';
import { Text, View } from 'react-native';
const supportEmail: string | undefined = Constants.expoConfig?.extra?.supportEmail;
export function SupportFooter() {
return (
<View>
<Text>Questions? Write to {supportEmail ?? 'our support team'}</Text>
</View>
);
}