reactjs - How do I handle environment configuration in react-native to point at DEV/TEST/Production -


i new rn , trying figure out how can utilize environment specific configuration.

for example, code have hitting server api needs change based on environment

const endpoint = "http://localhost:8282/api/v1/auth/" //staging endpoint "http://staging:8282/api/v1/auth" //production endpoint "http://production:8282/api/v1/auth"      export default {       login(fbid,fbaccesstoken,expiresin){         return fetch(endpoint + 'login', {           method: 'post',           body: json.stringify({             fb_id: fbid.tostring(),             access_token:fbaccesstoken,             expires:expiresin.tostring()           })         })       }     } 

you can check value of __dev__ in order achieve that.

your code should this

const endpoint = __dev__  ? "http://staging:8282/api/v1/auth/"                           : "http://production:8282/api/v1/auth" 

Comments