Issue
How can we set up .env
in react native application? How to do environment setup inside react-native.
Solution
I use 'react-native-dotenv' package. Install it and add "react-native-dotenv" preset to your .babelrc file at the project root, like this:
{
"presets": ["react-native", "react-native-dotenv"]
}
Then create a .env file and add your properties there, may be like this:
YOUR_FIELD="value"
finally, you should be able to use it in your src files, like this:
import { YOUR_FIELD } from 'react-native-dotenv';
console.log(YOUR_FIELD) // prints "value"
if you run into an issue while using this package, then you can look for further clarification in their GitHub page, right here: https://github.com/zetachang/react-native-dotenv
Hope this helps.
Answered By - Sabbir Ahmed Answer Checked By - Mary Flores (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.