1// step one install this module
2npm install react-native-dotenv
3
4// step two add this in your babel.config.js
5 plugins: [
6 'module:react-native-dotenv',
7 {
8 moduleName: '@dotenv',
9 safe: false,
10 allowUndefined: false
11 }
12 ]
13
14 // step three add value whatever in your .env file
15 API_KEY = 434d3c04fc285d218d740e2a568387e4
16
17 // step four use this method for call environment
18 import { API_KEY } from '@dotenv'
1# .env files
2API_URL=https://myapi.com
3GOOGLE_MAPS_API_KEY=abcdefgh
4
5# use env
6import Config from 'react-native-config'
7
8Config.API_URL // 'https://myapi.com'
9Config.GOOGLE_MAPS_API_KEY // 'abcdefgh'
10
11# call env
12development: ENVFILE=.env.staging react-native run-android
13production: cd android && ENVFILE=.env.production ./gradlew assembleRelease