Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environment variables inside React App #231

Open
ngmiduc opened this issue Dec 7, 2020 · 2 comments
Open

Environment variables inside React App #231

ngmiduc opened this issue Dec 7, 2020 · 2 comments

Comments

@ngmiduc
Copy link

ngmiduc commented Dec 7, 2020

Hi,

is there a way to include the NODE_DEBUG environment inside a React App?
As React filters all env variables our that aren't prefixed with REACT_APP_<name>.

best Minh

@SleepWalker
Copy link
Collaborator

Hello, @ngmiduc

If you'll provide some *_DEBUG env variable for you react app during build, this will hardcode that value in your code and it won't be possible to change it later at runtime. Do you really want this?

In any case, you can pass REACT_APP_DEBUG during build and then somewhere before running your app just mirror this value in localstorage:

window.localStorage.setItem('debug', process.env.REACT_APP_DEBUG)

@ngmiduc
Copy link
Author

ngmiduc commented Dec 9, 2020

Hi

I didn't mean to hard code it into build. I want to run it in development and I think the env variable NODEDEBUG gets filtered out by the react app since it only allows prefixed eng variables to be accessible in the app.

So when I initialize the logdown in some file in the app, it can not access the env Variable to check if the console logs are enabled or disabled.

I created now a separated file that imports logdown and sets the state by a react env variable. Do enable and disable the logs .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants