How to Declare a Global Variable in React?


If you need to declare a global variable in React, then you can do the following:

Create a file called config.js

module.exports = global.config = {
    something: {
        somethingelse: {
            amount: 123,
            name: "Andrew"
        }
    }
};

Then import the config file where you need it:

import './config';

Then where you need it in your code:

global.config.something.somethingelse.amount

or

global.config.something.somethingelse.name