Reputation: 2288
I need to read config.json file before my application will start. This config contains urls to my back-end services. Which will be used into redux action-creators.
I have 2 approaches:
What should i do ?
Upvotes: 3
Views: 2569
Reputation: 73938
You could consider the following solution:
IMO the main advantage of this approach is that you do not pollute the the global namespace and you keep things clean using a separate module. This approach could work best for static or dynamic configurations.
To be honest do not sure if your store is the right place to keep configuration as AFAIK it was designed for maintaining the state tree of your application so could be considered the right place in case your configurations are in some how dynamic.
Upvotes: 3
Reputation: 156
i will fetch json file and define it as global variable
fetch('config.json').then(data => window.CONFIG = data)
if config file contains some data which is relative to UI, you can set it to intialState in store
const initalState = { config: window.CONFIG }
Upvotes: 1
Reputation: 15914
I will choose approach 2 because it's config not state of your app. It won't change during runtime.
But I'm not sure what your app looks like, if your config does change dynamically then putting it in the redux store makes sense to me.
Upvotes: 2