react-native-config

react-native-config
Photo by Rahul Mishra / Unsplash

Install the library using

npm i react-native-config

After installing library create .env file at the root of your project with following code

# DEV, STAGE, PROD
APP_PROFILE=DEV
API_BASE_URL=http://10.0.1.32:6055/health-tracker
TENANT_ID=health-tracker

By plugin this config library we have to manually add code in 'android/app/build.gradle' file

apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"

Create a configs folder in src with 'AppConfig.js' and 'index.js' files with following code

import Config from 'react-native-config';

export default {
  APP_PROFILE: Config.APP_PROFILE,
  API_BASE_URL: Config.API_BASE_URL,
  TENANT_ID: Config.TENANT_ID,
  EXPERIMENTAL_FEATURES: {},
};
``
import AppConfig from './AppConfig';

export {AppConfig};

Now we have to access .env file fields by importing Appconfig file

Read more