Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Config Variables for React-Native Apps
Search
Pedro Belo
February 24, 2016
Programming
750
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Config Variables for React-Native Apps
Pedro Belo
February 24, 2016
Transcript
15 slides
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
Other Decks in Programming
See All in Programming
あなたはMCPの機能を、まだ知らない。
4geru
1
750
flutter_test のその先へ — Flutter アプリの LLM 機能に「評価」という品質保証を
kosukesaigusa
0
210
どうしても Eloquent でリポジトリパターンをやりたいんだ #phpcon_niigata / phpcon-niigata-2026
shogogg
0
710
コード生成時代のAPI定義を支えるRequest Spec移行
pvcresin
0
320
Canvas 2D Context Next
petamoriken
0
880
AI駆動TDD ― 2026年10月版
hrmstrsmgs
0
120
ビジネスロジックを堅牢に~Scala 3のドメインプリミティブ~
j5ik2o
0
240
Apache Airflow Introduction
leew
1
100
Going Full Circle with Virtual Graphs and Relational Databases
michaelsimons
1
120
JavaScriptはシングルバイナリの夢を見るか / Does JavaScript Dream of a Single Binary?
ssssota
1
1.2k
The Cost of the DOM
ypresto
6
3.3k
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
450
Featured
See All Featured
Highjacked: Video Game Concept Design
rkendrick25
PRO
2
600
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
50
10k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.3k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
500
The Invisible Side of Design
smashingmag
301
52k
Darren the Foodie - Storyboard
khoart
PRO
5
4.1k
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
400
Ruling the World: When Life Gets Gamed
codingconduct
0
450
AI: The stuff that nobody shows you
jnunemaker
PRO
12
1.3k
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
2
6.5k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
580
Google's AI Overviews - The New Search
badams
0
1.7k