gpt4 book ai didi

reactjs - Redux 状态应该如何剖析?

转载 作者:行者123 更新时间:2023-12-02 06:51:41 25 4
gpt4 key购买 nike

我在一个复杂的 React 应用程序中工作,该应用程序处理异步调用,这些调用带来了 Deeply Big JavaScript 对象。我想知道创建状态来存储这些对象的更好方法是什么。 Redux 文档说:

In a more complex app, you're going to want different entities to reference each other. We suggest that you keep your state as normalized as possible, without any nesting. Keep every entity in an object stored with an ID as a key, and use IDs to reference it from other entities, or lists. Think of the app's state as a database. This approach is described in normalizr's documentation in detail. For example, keeping todosById: { id -> todo } and todos: array inside the state would be a better idea in a real app, but we're keeping the example simple.

如果我只在我的状态中存储引用,我应该在哪里存储我的对象?

这个问题有意义吗?

什么对 Redux 状态更好?一个大的扁平状态?还是介质未扁平化状态?

最佳答案

对象也应该存储在 redux store 中。这个想法是您可以通过 ID 引用其他对象,而不是嵌套完整的对象。您可以查看此页面上的示例:http://redux.js.org/docs/recipes/reducers/NormalizingStateShape.html

关于reactjs - Redux 状态应该如何剖析?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42402120/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com