Answers for "reactjs some variable in .env not detected"

0

reactjs some variable in .env not detected

Based on accepted answer on this SO, Three things that your variable in .env will detected

1. the variable should be prefixed with REACT_APP_

eg: REACT_APP_WEBSITE_NAME=hello

2. You need to restart the server to reflect the changes.

3. Make sure you have the .env file in your root folder(same place where you have your package.json) and NOT in your src folder.

After that you can access the variable like this process.env.REACT_APP_SOME_VARIABLE

also additional tips

No need to wrap your variable value in single or double quotes.
Do not put semicolon ; or comma , at the end of each line.
NB: I'm not change the text to avoid confussion because my english is really bad.
Posted by: Guest on June-14-2021

Browse Popular Code Answers by Language