Reading environment variable from .env in React Custom MC app #2427
-
Hi there, I'm trying to use an environment variable to read a public key from a .env file in my Merchant Center Custom App. For example: In the
In the component code:
returns Usually the Is it possible to read environment variables in this way with the Custom MC App? Help much appreciated 🙏 Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi, sorry for the late reply. We don't support using environment variables like in CRA. However, you can define this kind of information in the Custom Application config file, using the https://docs.commercetools.com/custom-applications/development/application-config#additionalenv {
"additionalEnv": {
"publicKeyTest": "something"
}
} These "injected" values can be accessed in the client code using the import { useApplicationContext } from '@commercetools-frontend/application-shell-connectors';
const MyComponent = () => {
const publicKeyTest = useApplicationContext(
context => context.environment.publicKeyTest
);
// ...
}; |
Beta Was this translation helpful? Give feedback.
Hi, sorry for the late reply.
We don't support using environment variables like in CRA.
However, you can define this kind of information in the Custom Application config file, using the
additionalEnv
object.https://docs.commercetools.com/custom-applications/development/application-config#additionalenv
These "injected" values can be accessed in the client code using the
useApplicationContext
hook.…