Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Config Variables for React-Native Apps
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Pedro Belo
February 24, 2016
Programming
0
740
Config Variables for React-Native Apps
Pedro Belo
February 24, 2016
Tweet
Share
Other Decks in Programming
See All in Programming
組織で育むオブザーバビリティ
ryota_hnk
0
170
React 19でつくる「気持ちいいUI」- 楽観的UIのすすめ
himorishige
11
7.3k
インターン生でもAuth0で認証基盤刷新が出来るのか
taku271
0
190
例外処理とどう使い分ける?Result型を使ったエラー設計 #burikaigi
kajitack
16
6k
AI & Enginnering
codelynx
0
110
ぼくの開発環境2026
yuzneri
0
180
2026年 エンジニアリング自己学習法
yumechi
0
130
dchart: charts from deck markup
ajstarks
3
990
Rust 製のコードエディタ “Zed” を使ってみた
nearme_tech
PRO
0
160
AgentCoreとHuman in the Loop
har1101
5
230
カスタマーサクセス業務を変革したヘルススコアの実現と学び
_hummer0724
0
680
AIによる開発の民主化を支える コンテキスト管理のこれまでとこれから
mulyu
3
180
Featured
See All Featured
Embracing the Ebb and Flow
colly
88
5k
Build The Right Thing And Hit Your Dates
maggiecrowley
38
3k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
220
The Language of Interfaces
destraynor
162
26k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.6k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3.3k
The Spectacular Lies of Maps
axbom
PRO
1
520
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
77
Optimizing for Happiness
mojombo
379
71k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
320
RailsConf 2023
tenderlove
30
1.3k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
Transcript
Config Variables for React-Native apps
The problem var LuggApi = { request: async function(method, path)
{ let url = 'https://api.lugg.com' + path; let headers = { 'Authorization': 'Bearer 48616d6d65'} let response = await fetch(url, { method, headers }); // ... };
The problem(s) • Secret in repo • Hard to change
• Can’t reuse outside JS
Solving #1 // config.sample.js module.exports = { apiUrl: 'https://api.lugg.com', apiToken:
'CHANGEME' } // api.js var LuggApi = { request: async function(method, path) { let url = Config.apiUrl + path; let headers = { 'Authorization': 'Bearer ' + Config.apiToken } let response = await fetch(url, { method, headers }); // ... };
Solving #2 // config.js var dev = { apiUrl: 'http://localhost:5000',
apiToken: 'abcdefgh' }; var prod = { apiUrl: 'https://api.lugg.com', apiToken: '48616d6d65' }; module.exports = __DEV__ ? dev : prod;
Solving #3 android { productFlavors { dev { resValue "string",
"GOOGLE_MAPS_API_KEY", "abcdefg" } production { resValue "string", "GOOGLE_MAPS_API_KEY", "0123456" } } }
Solving #3
New problems • Inconsistent formats • Need a React Native
bridge • Can’t reuse across platforms
SOLVE ALL THE THINGS $ rnpm install react-native-config
.env API_URL=https://api.lugg.com API_TOKEN=48616d6d65 GOOGLE_MAPS_API_KEY=0123456
Consume from JS import Config from 'react-native-config' Config.API_URL // https://api.lugg.com
Config.API_TOKEN // 48616d6d65
Consume from Gradle android { signingConfigs { release { storeFile
file(project.env.get("RELEASE_STORE_FILE")) storePassword project.env.get("RELEASE_STORE_PASSWORD") keyAlias project.env.get("RELEASE_KEY_ALIAS") keyPassword project.env.get("RELEASE_KEY_PASSWORD") } } }
Consume from AndroidManifest.xml <meta-data android:name="com.google.android.geo.API_KEY" android:value="@string/GOOGLE_MAPS_API_KEY" />
Consume from Xcode
Thanks! @ped github.com/luggg/react-native-config