I have a react js project , but with typescript. I understand we can create .env file and have some configuration defined as such,
.env file
REACT_APP_SOME_CONFIGURATION = "some value"
and use it in the code , without importing anything , like below
const configValue = process.env.REACT_APP_SOME_CONFIGURATION
I tried this set up in my project , and it didn't work. is it because it is typescript? how to use .env file in such scenario.
In TypeScript, you need to set the return value so if this string did so
const configValue : string = process.env.REACT_APP_SOME_CONFIGURATION
OR
const configValue: string = (process.env.REACT_APP_SOME_CONFIGURATION as string);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With