Is store.dispatch in Redux synchronous or asynchronous

后端 未结 2 622
耶瑟儿~
耶瑟儿~ 2020-11-27 19:41

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

Is store.dispatch synchronous or asynchronous in Redux ?

相关标签:
2条回答
  • 2020-11-27 19:46

    Nobody knows better than the code itself. =) As you can see dispatch is absolutely synchronous. The only warning here is that store enhancers can (and do) substitute dispatch method. For example, take a look at applyMiddleware enhancer, it lets you jack middlewares in by replacing default dispatch method with its own implementation. Though I never saw any Redux enhancer which would actually remove synchronous nature of dispatch.

    0 讨论(0)
  • 2020-11-27 20:05

    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?

    0 讨论(0)
提交回复
热议问题