Should I keep the static configuration in abbreviation?

I am creating a reaction / reduction web application and I wonder where I need static configuration information that never changes (while the web application is running anyway).

This is the data in question

This information is used in different parts of the application, for example: there is a form in which you can select any element from the main array and thereby fill another selection field with the properties of the selected array:

<select>Choose an exchange</select> <select>Choose a market (that is available in the above exchange)</select> 

This lends itself well to some reducer logic (which sets state.markets based on what is selected in the first select ), but whether it should be filtered based on a different state in the tree or just load the data into the closure inside the reducer (keeping everything unrelated to state tree)? Or is this not a state at all (and should the container load this file and filter based on one state.exchange state state.exchange )?

When the form is filled in, the result will be processed as follows:

 {exchange: 'a', market: 'b'} 

So, this will also be a state (I think?)

+5
source share
1 answer

My understanding of redux is that we should only store state data in the store , that is, data that can be changed. Static data is by definition stateless and therefore should not be tracked as such.

As a result, I usually have a file /common/app-const.js , where I store these types of static objects. In your case, you can simply move all the static data from exchange.js to a shared file, which you then import , where you need it.

/common/app-const.js

 export default { markets: [ { pair: ['USD', 'BTC'], minimalOrder: { amount: 0.01, unit: 'asset' } }, { pair: ['RUR', 'BTC'], minimalOrder: { amount: 0.01, unit: 'asset' } }, { pair: ['EUR', 'BTC'], minimalOrder: { amount: 0.01, unit: 'asset' } }, ... } 

I understand your approach, however it would be nice to just enter your data using connect() via react-redux , however its a little easier just import static data from the file where necessary.

0
source

Source: https://habr.com/ru/post/1258609/


All Articles