Reputation: 399
I define REACT_APP_ADMIN_URL in my .envrc file, i want to use it as a component link, but i get only empty or undefined
This my environment variable, in file .envrc
REACT_APP_ADMIN_URL="http://127.0.0.1:8000/admin"
in file consts.js i make
export const ADMIN_URL = process.env.REACT_APP_ADMIN_URL;
and in my page i make this
import { ADMIN_URL } from './Consts';
<Menu href={ADMIN_URL}>Admin</Menu>
but doesnt work, in my inspector console i get this
<a href="#" role="menuitem" tabindex="-1">Admin</a>
Upvotes: 0
Views: 1938
Reputation: 255
I think that you have to load the environment variables from the .env file on runtime, you can use dotenv package to do so.
npm i dotenv
require('dotenv').config()
before using the environment variables on your code.Upvotes: 1