react-native-config /react-native-config

Bring some 12 factor love to your mobile apps!

★ 4,951⑂ 656👁 28⑃ 330● 594▤ 37
RubyMITCreated 2016-02-23
下载:v1.7.2v1.7.2 ↓1.7.22026-08-28
+0
日增长
4,951
stars
656
forks
28
watchers
330
prs
594
issues
37
releases

README

react-native-config


  Config variables for React Native apps, supporting iOS, Android, macOS and Windows.


Expose config variables to your JavaScript code — bring some
12 factor love to your mobile apps!

 [!TIP]
 Help keep this library maintained. If react-native-config is useful to you or your
 company, please consider
 sponsoring it on Open Collective.
 Contributions go toward the maintenance work that keeps it working across new React Native
 releases. See Sponsors for the tiers and what sponsorship pays for.

 Basic Usage

Create a new file .env in the root of your React Native app:


API_URL=https://myapi.com
GOOGLE_MAPS_API_KEY=abcdefgh


Then access variables defined there from your app:

js
import Config from "react-native-config";

Config.API_URL; // 'https://myapi.com'
Config.GOOGLE_MAPS_API_KEY; // 'abcdefgh'


Keep in mind this module doesn't obfuscate or encrypt secrets for packaging, so do not store sensitive keys in .env. It's basically impossible to prevent users from reverse engineering mobile app secrets, so design your app (and APIs) with that in mind.

 Setup

 ✅ The latest version of react-native-config is tested with React Native 0.87 (New
 Architecture) — see the example app. On Windows it is tested with
 react-native-windows 0.79, the newest React Native version react-native-windows
 supports today — see the Windows example app.

 ⚠️ Note (Android): react-native-config v1.6.0+ requires React Native 0.74 or higher.  
 If you use an older RN version, see Troubleshooting below.

Install the package:


$ yarn add react-native-config


Link the library:

On React Native 0.60 and above there is no link step — the library is
autolinked.
Rebuild the app so the native side is picked up. On iOS / macOS, install the pod first:


(cd ios; pod install)


 [!WARNING]
 Do not link this library manually on React Native 0.60 or above, and do not disable its
 autolinking in react-native.config.js. Autolinking is what registers the native module and,
 on the New Architecture, generates its TurboModule bindings — adding
 include ':react-native-config' to android/settings.gradle instead does neither, and the
 module then resolves to null at runtime. See
 TypeError: Cannot read property 'getConfig' of null.

(Note: For Windows, this module supports autolinking when used with [email protected]
or later. For earlier versions you need to manually link the module.)


Manual linking — only for React Native below 0.60, or react-native-windows below 0.63


$ react-native link react-native-config


(react-native link was removed from the React Native CLI; it is only available on the older
versions these instructions apply to.)

 - Manual Link (iOS / macOS)

	1. In XCode, in the project navigator, right click Libraries ➜ Add 		Files to [your project's name]
	2. Go to node_modules ➜ react-native-config ➜ ios  and add 		ReactNativeConfig.xcodeproj
	3. Expand the ReactNativeConfig.xcodeproj ➜ Products folder
	4. In the project navigator, select

Top issues

Latest release

v1.7.2 v1.7.2 2026-08-28
Documentation

 add funding metadata and a sponsor tier section by @luancurti in https://github.com/react-native-config/react-native-config/pull/891

 Chores

 ios: accumulate dotenv values without copying the hash by @OskarEichler

 New Contributors
 @OskarEichler made their first contribution in https://github.com/react-native-config/react-native-config/pull/891

Full Changelog: https://github.com/react-native-config/react-native-config/compare/v1.7.1...v1.7.2

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON