Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I pass arguments to react-scripts start command and use them in react?

I have a .sh file with the follow code:

react-scripts start HOST=0.0.0.0

And my yarn start scripts is:

"scripts": {
"start": "./run.sh",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"

},

The problem is that when I access to process.env object on a react component, I don't see this variable. How can I do this to work?

like image 962
kevin parra Avatar asked Oct 26 '25 06:10

kevin parra


1 Answers

This seem to work for me: Setting environment variables in a shell script for a React app

So the solution is to add REACT_APP as prefix of your variables.

My .sh file ended like this:

#!/bin/sh
export REACT_APP_PYTHON_API_IP="localhost"
yarn start
like image 187
kevin parra Avatar answered Oct 29 '25 09:10

kevin parra



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!