TeodorKolev TeodorKolev - 1 year ago 534
React JSX Question

React create constants file

How to create constants file like: key - value in ReactJs,

ACTION_INVALID = "This action is invalid!"

and to use that in other components

errorMsg = myConstClass.ACTION_INVALID;

Answer Source

You can simply create an object for your constants:

const myConstClass = {
    ACTION_INVALID: "This action is invalid!"

And then use it.

If you are bundling, you can export this object and then import for each component file.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download