PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, August 19, 2022

[FIXED] How can we set up .env in react native application?

 August 19, 2022     environment-variables, react-native     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing