Home > other >  Is it possible to share environment variables between two react app running along with?
Is it possible to share environment variables between two react app running along with?

Time:09-28

I have a small project, a chart app A, that need to embedded into an web app B. They are both React app.

App A will need an env variable called WS_ENDPOINT_URL to open a connection to websocket. After building app A into bundle, and embedded into web app B. The way of embedding is:

  • Import A bundle file into a React component
  • Create Chart instance, then call method to render it on the web app B

so I wonder how could I input WS_ENDPOINT_URL for A bundle to work?

Is there any way to share env variable from app B to app A? like from parent to child?

Any suggestion would be appreciated!

CodePudding user response:

Yes you can do that, but you have to use some kind of Secrets Manager like Doppler https://www.doppler.com/

CodePudding user response:

Give me a lil bit more context here.

  • are both apps created with create-react-app ? -- If yes you need to create an .env file on each project with the same variables such as WS_ENDPOINT_URL
  • those the embedded app needs to be an app ? -- If not why not instead of been an app why not a component create a component publish it and import it as dependency ?

Tell me more of the building process how is it done and I can help u

  • Related