TeodorKolev TeodorKolev - 3 months ago 88
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

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.