Comments (3)
In case anyone else wants to implement this, I've found an easy solution that works well. I'm using https://github.com/niftylettuce/dotenv-parse-variables to parse the variables provided by react-native-config
.
Here's an example .env
file:
STRING="https://www.google.com"
EMPTY_STRING=
BOOLEAN=true
NUMBER=5
Here's the code:
// env.js
import Config from 'react-native-config';
import dotenvParseVariables from 'dotenv-parse-variables';
const ENV = {
STRING: Config.STRING,
EMPTY_STRING: Config.EMPTY_STRING,
BOOLEAN: Config.BOOLEAN,
NUMBER: Config.NUMBER,
};
dotenvParseVariables(ENV);
export default ENV;
The ENV
object using the values directly from react-native-config
(before parsing using dotenv-parse-variables
) looks like this:
{
"STRING": "https://www.google.com",
"EMPTY_STRING": "",
"BOOLEAN": "true",
"NUMBER": "5"
}
And after parsing using dotenv-parse-variables
, it looks like this:
{
"STRING": "https://www.google.com",
"EMPTY_STRING": "",
"BOOLEAN": true,
"NUMBER": 5
}
from react-native-config.
I'd encourage you to do that in JS land! Maybe define your own Config
module, that sits between your app and this package, casting values accordingly?
Long term I'd love to support different types, but since .env
doesn't have it we'd have to either use another format to define the env (most likely json) or allow apps to somehow configure this package telling it what config it needs and what are their types. For a reference this is exactly what we've done in Pliny, a Ruby framework, so I think this could work well!
Let me know if you do this in your app or want to take a stab at a pull here! Closing in the meantime.
from react-native-config.
Hi @pedro,
Thanks for your help. I made the cast with JS, as you suggested. The idea of supporting different types is really cool.
from react-native-config.
Related Issues (20)
- Variable are UNDEFINED on IOS HOT 14
- Could not find method android() for arguments [dotenv_4bgzrl46y7i0xnvnmgzr6qa4c$_run_closure1@3fa75e8b] on project ':app' of type org.gradle.api.Project.
- How to read config in Kotlin class in react native 0.73? HOT 1
- RNConfig Empty Android HOT 2
- MainApplication.kt:27:58 Type mismatch: inferred type is String but Boolean was expected HOT 1
- Not working on ReactNative 0.73 HOT 1
- Error retrieving namespace value from .env file during build process
- hey, did you find a way to make it work?
- Update the documentation HOT 3
- Issue with kotlin DSL
- ios undefined problem HOT 7
- [Question] - Is this lib abandoned?
- Compatibility of react-native-config with React Native 0.73+ HOT 1
- Visionos podspec misconfiguration resulting in build failure HOT 3
- App crashes on launch when using in `GoogleService-Info.plist` on iOS
- App crashes on android release build HOT 2
- [Question] Windows: Package.appxmanifest
- Build error on iOS app with react-native 0.73.6 HOT 1
- Update example react-native version
- Environment Variables Not Applied in Release Build Using react-native-config
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-config.