Is it a good idea to keep huge data object in a single store of Redux?

本小妞迷上赌 提交于 2019-12-24 23:48:26

问题


As Redux provides store for keeping all application data in one place, Is it good practice to keep data in single large object? What if we have thousands of records and their data which is large in size, will it affect on application performance?


回答1:


This is a good place to start Redux Performance

For maximum rendering performance in a React application, state should be stored in a normalized shape, many individual components should be connected to the store instead of just a few, and connected list components should pass item IDs to their connected child list items (allowing the list items to look up their own data by ID). This minimizes the overall amount of rendering to be done. Use of memoized selector functions is also an important performance consideration.

Regarding the large state object in Redux

Immutably updating state generally means making shallow copies, not deep copies. Shallow copies are much faster than deep copies, because fewer objects and fields have to be copied, and it effectively comes down to moving some pointers around.

However, you do need to create a copied and updated object for each level of nesting that is affected. Although that shouldn't be particularly expensive, it's another good reason why you should keep your state normalized and shallow if possible.

As mentioned by @MatanHafuta, it is very important how your state object looks like.

You can use a package like normalizr to normalize JSON data that has deeply nested objects.




回答2:


It really doesn't matter, eventually you hold the same data, just make sure to organize your data in a way it will be easy and fast to retrieve and manipulate, it's not the amount of data but the way you organize your data in an efficient way, also consider the ease of updating the state in reducers, logical division is something to think about before writing code.



来源:https://stackoverflow.com/questions/49586234/is-it-a-good-idea-to-keep-huge-data-object-in-a-single-store-of-redux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!