Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set up custom developer options in React Native

Is it possible to add custom developer options to your React Native app? For instance I would like to add the possibility to change the endpoint to which the app connects so I can switch between localhost, staging, production etc. on my mobile phone

like image 657
Mahoni Avatar asked Mar 09 '23 18:03

Mahoni


2 Answers

With webpack you can use proccess.environment plugin, so you will be able to use

if (process.env.NODE_ENV === 'dev')  {
  makeYourThingIncludingRequereETC();
}

https://github.com/webpack/docs/wiki/list-of-plugins#environmentplugin

it will be transpiled to if ('prod' === 'dev') {} in prod environment before build and minification, which will be removed from code due to 'always false' rule.

like image 184
zb' Avatar answered Mar 16 '23 22:03

zb'


The best way to configure your react native app for different environments is to use

react-native-config

like image 42
Satya P. Goyal Avatar answered Mar 16 '23 21:03

Satya P. Goyal