react-native-dotenv
react-native-dotenv copied to clipboard
How to reset the env variables?
How can I change the variables in the .env
file and see the changes immediately?
According to the docs, make a change to the file importing the variables and you'll see the change immediately; even whitespace works.
@alizahid this approach doesn't work for me.
this works for me
it doesnt work for me
doesn't work for me
Just to be clear, here are the steps;
- Update
.env
- Go to file which is importing the variable;
import { MY_VAR } from 'react-native-dotenv'
- Make some changes to the file; any change will do. If Git recognizes a change, it should do the trick
- Save the file
- Reload in simulator / device
- Profit
Sometimes, step 4 can be a bit tricky. Eg, my editor removes unnecessary whitespace on save. So I have to be careful where I add spaces for it to register as a change. But otherwise, this has worked flawlessly for me.
@PolGuixe @KirillPd @kanso-git @DoWhileGeek @jameskennethrobinson Hope this helps!
npm start -- --reset-cache
.
This worked for me . Sometimes I make the variable name wrong in the .env file just to verify.
⬆️ After finished to reset cache, to reload the app the press "r". This worked for me.
I don't think there is a consistent answer to this.
Modified steps using Expo
- Update
.env
- Go to EVERY file which is importing the variable;
import { MY_VAR } from 'react-native-dotenv'
- Make some changes to EVERY file which is importing the variable; any change will do. If Git recognizes a change, it should do the trick
- Save the file
- Restart metro bundler (hit
r
in terminal whereexpo start
is running - Reload in simulator / device
- Cringe