Advice on wether I should use derived state and re-selectors or duplicate objects to gain in performance #4119
-
I'm doing an application to gather stock for orders and check what have been requested in orders. For this I use react with redux for managing application state. In the view of the list of products I see the total amount to prepare for all the orders, summarized formats with quantities requested for each format for all the orders, observations and total stock and some other information I dont describe for simplicity. I can set the total quantity the warehouse can prepare for all the orders and click prepared. Meanwhile in the delivery note view I can view each product with the same properties I have described before for that order and modify the quantity the warehouse can prepare only for this order which will have influence later on the products list view too. Right now in my redux state I have two objects. The products which contain summarized state of the application for all the orders and the orders which contain nested products state. So the products are kind of duplicated. When modifying quantites from one view or another I updated in the reducers both objects of the state. My question is: Should I have just orders with products and use Redux Reselect or selectors for rendering the products list which will be derived from the orders and avoid duplicating the products object on the state and also simplify the logic of updating the state(right now I have to update both of the objects for each operation involving quantities)? If I do this would it perform well like with how it's done right now? I ask this because the products also have more complex properties. So when rendering the list of products all of that logic for each products will have to be calculated with the selectors.I'm not sure if selectors and Redux Reselect are the best approach for complex calculations and lots of properties. Also I'm open to use any other approach that would be better that I haven't described here. I just want to reduce state updating logic and simplify my state without making the load of the pages heavy. TL DR: Complexity vs performance. I have an orders app that have products which can be viewed on a summarized list of the products for all the orders or just the products for one order. I'm doubting between having in state what is used in each view(products and orders with products) so it renders allegedly fasters because the objects to use are already calculated for each view but the update is more tedious because I have to update orders and products VS deriving the products from orders state which I don't know if it's efficient |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
See Deriving Data with Selectors - we recommend using selectors for deriving data to avoid stale state. You can memoize anything expensive to avoid excessive recalculations. |
Beta Was this translation helpful? Give feedback.
they'll handle it better than reducers :)