问题描述
我目前正在尝试概念化如何在另一个组件中分派后根据数据更改处理在组件中分派动作.
I am currently trying to conceptualize how to handle dispatching an action in a component based on a data change after a dispatch in another component.
以这个场景为例:
dispatch(someAjax)
-> 状态更新中的属性.
dispatch(someAjax)
-> property in state updates.
在此之后,我需要另一个依赖于相同属性的组件来知道它已更新并根据新值调度操作.
After this, I need another component dependent on this same property to know that is has updated and dispatch an action based on the new value.
与使用某种类型的 value.on(change...
解决方案相比,处理此类级联"操作的首选方法是什么?
Rather than using some type of value.on(change...
solution, what is the preferred way to handle this type of action 'cascading'?
推荐答案
有两种基本方法:一种是在动作完成后区分状态的中间件,另一种是使用 Redux 的低级 store.subscribe代码> API.
There are two basic approaches: either a middleware that diffs the state after an action is done, or using Redux's low-level store.subscribe
API.
Redux 常见问题有 涵盖此内容的答案.此外,我保留了一份 Redux 相关插件和实用程序的分类列表,其中包括一组 现有的存储更改订阅库,它们实现了各种方法来侦听数据更改.
The Redux FAQ has an answer that covers this. Also, I keep a categorized list of Redux-related addons and utilities, and that includes a group of existing store change subscription libraries that implement various approaches to listening for data changes.
这篇关于如何在调度操作后侦听 Redux 存储中的特定属性更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!