Skip to content

remscodes/react-native-config-info

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

React Native Config Info

Read configuration values from Info.plist (iOS) or from resources strings.xml (Android)

github ci npm version bundle size license

Installation

npm install react-native-config-info
cd ios && pod install

Prerequisite

Add your values into your Info.plist (iOS) or strings.xml (Android).

iOS

ios/[project]/Info.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>BackendUrl</key>
    <string>https://api.example.com</string>
</dict>
</plist>

Android

android/app/src/main/res/values/strings.xml

<resources>
    <string name="BackendUrl">https://api.example.com</string>
</resources>

Usage

Asynchronous getters

Get your values.

import ConfigInfo from 'react-native-config-info';

async function main() {
  await ConfigInfo.get('BackendUrl'); // https://api.example.com
  await ConfigInfo.getOrThrow('BackendUrl'); // https://api.example.com

  await ConfigInfo.get('UnknownKey'); // null
  await ConfigInfo.getOrThrow('UnknownKey'); // [RNConfigInfoException: 'UnknownKey' value is missing from ….]
}

Synchronous getters

Get your values synchronously.

As said in the official documentation, synchronous methods are not recommended.

Only use them if you have no other option.

import ConfigInfo from 'react-native-config-info';

ConfigInfo.getSync('BackendUrl'); // https://api.example.com
ConfigInfo.getSyncOrThrow('BackendUrl'); // https://api.example.com

ConfigInfo.getSync('UnknownKey'); // null
ConfigInfo.getSyncOrThrow('UnknownKey'); // [RNConfigInfoException: 'UnknownKey' value is missing from ….]

License

MIT © Rémy Abitbol.

About

🔎 Read configuration values from Info.plist (iOS) or from resources strings.xml (Android)

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •