Easy ReactJS config management

Easy ReactJS config management

For config management in ReactJS project I recommend using react-global-configuration NPM module. Three short steps for using it:

Install

npm install react-global-configuration --save

Create config

Create config.js file in any place you like. I prefer storing it in the root of a project:

import config from 'react-global-configuration';

config.set({
    someApiUrl: 'http://some-service.com/api'
});

export default config;

Use it

Now you are ready to use the config file in any React component:

import config from '../config';

return fetch(`${config.get('someApiUrl')}/users/authenticate`, requestOptions)

Author: vlad