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
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
GISエンジニアから見たLINKSデータ
nokonoko1203
0
190
Rubyで鍛える仕組み化プロヂュース力
muryoimpl
0
270
안드로이드 9년차 개발자, 프론트엔드 주니어로 커리어 리셋하기
maryang
1
150
tsgolintはいかにしてtypescript-goの非公開APIを呼び出しているのか
syumai
7
2.4k
[AI Engineering Summit Tokyo 2025] LLMは計画業務のゲームチェンジャーか? 最適化業務における活⽤の可能性と限界
terryu16
1
200
0→1 フロントエンド開発 Tips🚀 #レバテックMeetup
bengo4com
0
450
GoLab2025 Recap
kuro_kurorrr
0
790
Flutter On-device AI로 완성하는 오프라인 앱, 박제창 @DevFest INCHEON 2025
itsmedreamwalker
1
170
フルサイクルエンジニアリングをAI Agentで全自動化したい 〜構想と現在地〜
kamina_zzz
0
340
AI前提で考えるiOSアプリのモダナイズ設計
yuukiw00w
0
210
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
560
Developing static sites with Ruby
okuramasafumi
0
340
Featured
See All Featured
Measuring & Analyzing Core Web Vitals
bluesmoon
9
720
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
990
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
1
1.4k
How to train your dragon (web standard)
notwaldorf
97
6.5k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
1
330
The Pragmatic Product Professional
lauravandoore
37
7.1k
The Language of Interfaces
destraynor
162
26k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
0
990
What the history of the web can teach us about the future of AI
inesmontani
PRO
0
380
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
71
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.2k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
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