【发布时间】:2019-10-22 16:28:08
【问题描述】:
我有带有 Redux 的 React 应用程序,其结构如下:
<ComponentParent>
<ComponentA></ComponentA>
<ComponentB></ComponentB>
</ComponentParent>
在组件 A 的 ComponentDidMount 中,调用 fetch 并异步返回数据。然后调用 Reducer 将数据添加到存储中。 然后组件 B 访问 store 以访问 A 添加到 store 中的数据。
可以预见的是,组件 B 在组件 A 发生更改以将数据写入存储之前访问数据(因为数据来自 aync fetch)。
问题:
- 设计这种交互的正确方法是什么?
- 我需要使用吗 方法类似于 react redux with asynchronous fetch ?请注意,在 Reducer 中,我只存储由异步返回的数据 组件 A,与链接中的不同
谢谢
【问题讨论】: