将大量数据对象保存在 Redux 的单个存储中是个好主意吗?

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

由于 Redux 提供 store 将所有应用程序数据保存在一个地方,将数据保存在单个大型 object 中是否是一种好的做法?如果我们有数千条记录并且它们的数据量很大,它会影响应用程序性能吗?

这真的没关系,最终您持有相同的数据,只需确保以一种易于快速检索和操作的方式组织您的数据,重要的不是数据量,而是你以有效方式组织数据的方式,还要考虑在 reducer 中更新状态的难易程度,逻辑划分是编写代码之前要考虑的事情。

这是一个很好的起点 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.

关于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.

正如@MatanHafuta 所提到的,状态对象的外观非常重要。

您可以使用像 normalizr 这样的包来规范化 JSON 具有深层嵌套对象的数据。