1. The problem
When developing a React Native app, you typically need to manage configurations for various environments, like development, testing, and production. You may also need to adjust configurations for different app features or components, which can be time-consuming and error-prone if done manually. Configu helps streamline environment-based configuration in a React Native app, reducing the potential for manual errors. This guide will demonstrate how to use Configu to manage configurations for your React Native app. Let’s begin by creating a simple Expo project and introduce environment variables to our React Native app by following the “Environment variables in Expo” guide. You should now have the following.env file:
.env file with more environment variables:
EXPO_PUBLIC_POST_BUTTON_ENABLED: A feature flag that determines whether the post button is enabled.EXPO_PUBLIC_POST_BUTTON_COLOR: The color of the post button.
.env file. This is not a good practice and can lead to errors. This is where Configu comes in, you can store all your configurations in one place and use the Configu CLI to export the configurations to your .env file based on the environment you are working on. In the next steps we will show you how to do this.
2. Install Configu CLI
3. Create schema declaration
Run the following command which will create a ConfigSchema using the.env file you created earlier and set the values as defaults.
expo.cfgu.json file in your project directory with the following content:
4. Connect to Configu ConfigStore
You may now choose one of the many ConfigStore integrations that are available as your source of configurations for your React Native app. In this guide, we will use the Configu ConfigStore our chosen ConfigStore.The Configu
ConfigStore is a convenient way to get started with Configu, especially for users who are new to the tool. It is a configuration management platform that is easy to use and requires minimal setup, with a free starter plan option.To get started with Configu Platform, you’ll need to register and create a new organization.5. Upsert values
Now that you have connected to the ConfigStore, you can upsert the configuration values for the different environments using the Configu CLI. You can upsert fallback configurations for each environment by upserting to the root set and adding environment specific configurations by upserting to the environment as such:6. Export and use values from Configu in your React Native app
.env file with the configurations declared in the “expo” ConfigSchema and their values from the “development” ConfigSet.
.env files with the configurations for those environments.
Staging:
.env file reflected in your React Native app. If you use a framework other than Expo, you can refer to the documentation of that framework to learn how to use environment variables.