If you want to use custom names that you want to pass into your ReactJS web application without having to hard code strings in your code, Well, it can be done.
I am using REACTJS for my web client with NPM to build and download my web apps dependencies. With npm there is a package.json file. This file defines your web applications dependencies, required scripts and required browser list.
in the package.json file you can add custom name value pairs that you can reference in your Reactjs Web application. This allows you to add all of your customizations to the package.json file and not be hardcoded in your code. So, how do you do this? Edit your package.json file and add what you want for your customizations. For example:
“MyName”: “My Custom Name”,
“MyVersion”: “My custom Version”,
“MyTitle”: “My Custom Title”,
Now to access these values in your ReactJs code, do the following:
var pjson = require(‘../package.json‘); // imports the package.json file
this.name = pjson.MyName;
this.version = pjson.MyVersion;
this.title = pjson.MyTitle;
Well, that is it. I find this a very useful feature for allowing for application customization.