How do you manage your expo phone app’s configuration between testing and production?
Expo has a feature called release channels that allow you to distribute different
versions of your app. In this post I’ll go over my approach to configuration management
of a react native app using release channels.
The relevant part of the expo docs are at Release Channels.
Here they demonstrate using the code like this
I had several questions when reading this snippet. Is releaseChannel a global variable?
Is App the component at the root of my project (App.js)? Does this go in version control?
The answers are:
releaseChannel is an argument to this function. You can read the value from the Constants api.
App here is an object holding all the environment variables.
Yes this goes in version control. There is no way to add secrets to your app securely.
After struggling to understand how to do this I ended up with the following approach.
Which can be used throughout your app like so
Some advantages here:
We use a single lookup variable (environments). You can get the environment by reading out the value by key.
We factor out common values into commonConfig. This slims down the size of the lookup object.
Its easy to override commonConfigs if a particular environment needs to.
I actually demonstrate how to use the expo Constants api.
One potential downside is that we don’t do partial matching of the release channel name like in the expo docs. But in my experience relying on .indexOf() can be error prone and it’s probably a better idea to be more explicit when matching your environments by name.
If you need help solving your business problems with
software read how to hire me.