Redux 中的 store.dispatch 是同步的还是异步的 [英] Is store.dispatch in Redux synchronous or asynchronous

查看:98
本文介绍了Redux 中的 store.dispatch 是同步的还是异步的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我意识到这是一个基本问题,但我没能在别处找到答案.

I realize this is a basic question but I had no luck finding the answer elsewhere.

store.dispatchRedux 中是同步的还是异步的?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆