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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
500
副作用をどこに置くか問題:オブジェクト指向で整理する設計判断ツリー
koxya
1
590
LLM Observabilityによる 対話型音声AIアプリケーションの安定運用
gekko0114
2
420
OSSとなったswift-buildで Xcodeのビルドを差し替えられるため 自分でXcodeを直せる時代になっている ダイアモンド問題編
yimajo
3
610
CSC307 Lecture 03
javiergs
PRO
1
490
例外処理とどう使い分ける?Result型を使ったエラー設計 #burikaigi
kajitack
16
6k
Spinner 軸ズレ現象を調べたらレンダリング深淵に飲まれた #レバテックMeetup
bengo4com
1
230
そのAIレビュー、レビューしてますか? / Are you reviewing those AI reviews?
rkaga
6
4.5k
SourceGeneratorのススメ
htkym
0
190
Smart Handoff/Pickup ガイド - Claude Code セッション管理
yukiigarashi
0
130
AI Agent Tool のためのバックエンドアーキテクチャを考える #encraft
izumin5210
6
1.8k
AI Schema Enrichment for your Oracle AI Database
thatjeffsmith
0
250
Featured
See All Featured
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
0
270
Context Engineering - Making Every Token Count
addyosmani
9
650
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
77
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
The SEO Collaboration Effect
kristinabergwall1
0
350
Design in an AI World
tapps
0
140
Navigating Weather and Climate Data
rabernat
0
100
So, you think you're a good person
axbom
PRO
2
1.9k
The Language of Interfaces
destraynor
162
26k
Product Roadmaps are Hard
iamctodd
PRO
55
12k
What's in a price? How to price your products and services
michaelherold
247
13k
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