What is the best way to store data in the Redux Store, the data that we received from the API are raw data or already computed data needed for output?
For example, the page displays three values in separate components: Value1 , Value2 , Value3 . These values are computed, i.e. for each of these values, to calculate them, several API requests are performed to obtain the necessary data. Those.
Value1 - request data 1 (for example, array [{id: 1, count: 1, amount: 100, ...}]) count = 1, request data 2 which depend on request 1.
Value2 - request data 1 (for example, array [{id: 1, count: 1, amount: 100, ...}]) amount = 100, request data 3
Value3 - request data 4.
In addition to all, Node.js sends more notifications about changed data. Those. an event comes that the element with id = 1 has changed in the data, and the data itself: {id: 1, count: 2, amount: 100, ...}. After that, it is necessary to recompute Value1 and Value2 , since element with id = 1 changed
It’s still better to organize, because in the case of already computed values, we have very simple components associated with the redux store:
class Container1 extends Component { render() { let { value1 } = this.props; return ( <div> {value1} </div> ) } } connect(function(state) { return { value1: state.value1 } } )(Container1) But how in this case to control the changed data? Reassign both Value1 and Value2, and in the case of a change, only then do dispatch with a new calculated value? After all, if there were raw data then I would make an array change and the values themselves would be recalculated, here I mean:
class Container1 extends Component { render() { let { fetchedData1, fetchedData2} = this.props; let value1 = Service.calculateValue1(fetchedData1, fetchedData2); return ( <div> {value1} </div> ) } } connect(function(state) { return { fetchedData1: state.fetchedData1, fetchedData2: state.fetchedData2 } } )(Container1) The first option looks certainly more attractive, but how to organize it, how to control changes in raw data, to calculate only the necessary values and put in the redux store?