Redux 中的 store.dispatch 是同步的还是异步的 [英] Is store.dispatch in Redux synchronous or asynchronous
问题描述
我意识到这是一个基本问题,但我没能在别处找到答案.
I realize this is a basic question but I had no luck finding the answer elsewhere.
store.dispatch
在 Redux
中是同步的还是异步的?
Is store.dispatch
synchronous or asynchronous in Redux
?
如果它是异步的,是否有可能在动作传播后添加回调,因为 React
可以实现?
In case it is asynchronous is there a possibility to add a callback after the action has been propagated as it is possible with React
?
推荐答案
AFAIK,调度动作是同步的.如果您愿意处理异步调用,您可以在 redux 中使用 thunk-middleware,其中 dispatch 作为回调函数提供,您可以根据自己的方便调用.有关更多信息,请查看作者自己在 SO 上的答案:如何在超时时分派 Redux 操作?
AFAIK, dispatching action is synchronous. In case if you are willing to address the asynchronous call, you can use the thunk-middleware in redux, where dispatch is provided as a callback function which you can invoke as per your convenience. For more info, checkout this answer on SO by Author itself: How to dispatch a Redux action with a timeout?
这篇关于Redux 中的 store.dispatch 是同步的还是异步的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!