shellscape / jsx-email

Build emails with a delightful DX
https://jsx.email
MIT License
902 stars 28 forks source link

Usage of environment variables #91

Closed aidan-rypens closed 7 months ago

aidan-rypens commented 7 months ago

Hello!

What's the best practice for using environment variables? This project is using VITE, but I cannot seem to access environment variables.

Couldn't find anything in either this documentation or the fork .react-email. Looked a common use case (to me).

shellscape commented 7 months ago

It's actually never come up before as a need. There are three environments the code runs in;

Because it's React/JSX at the end of the day, the recommendation is to use component props to set all of the data. Then, based on what your target running environment is, you can use envars appropriately to set the props.

aidan-rypens commented 7 months ago

It's actually never come up before as a need. There are three environments the code runs in;

  • React in the browser
  • React in the browser via Vite (preview app)
  • A regular Node process (call to render)

Because it's React/JSX at the end of the day, the recommendation is to use component props to set all of the data. Then, based on what your target running environment is, you can use envars appropriately to set the props.

Thanks @shellscape. Passing through with props is definitely a good way. It didn't came up to my mind at first. Thanks for the suggestion!