Open amcsi opened 6 years ago
You could set your env variable to a empty string and check its length to determine if it's been set or not. For example:
In .env:
MOCK_CURRENT_LOCATION=
In your code somewhere:
import { MOCK_CURRENT_LOCATION } from 'react-native-dotenv';
export default SomeClass extends React.Component {
render() {
if (MOCK_CURRENT_LOCATION.length > 0) {
return (<SomeView></SomeView>);
}
return (null);
}
}
Hope that helps!
Thanks, but it would be nicer to not have to define all the optional environment variables like in other dotenv libraries for other programming languages.
Any success on this?
I'm importing MOCK_CURRENT_LOCATION_LATITUDE from react-native-dotenv, however I'm not expecting it to always be set, and thus in the code I check with an if to see if it's set.
Instead I get Try to import dotenv variable "MOCK_CURRENT_LOCATION_LATITUDE" which is not defined in any .env files. and a redbox error for it even though I intentionally do not want it set in my env.
What am I supposed to do to have optional environment variables?