【发布时间】:2021-09-25 14:33:43
【问题描述】:
假设这是我的 thunk:
const thunk = async (dispatch,getState) =>{ 'some dispatch and await code'}
所以当我想发送这个 thunk 时,我应该使用 await dispatch(thunk) 还是只使用 dispatch(thunk)?
从 Redux-thunk 和 Redux 的源代码来看,我认为我应该使用 await dispatch(thunk),因为 redux-thunk 不会为我添加“等待”。但是如果我不使用 await 会发生什么(它只是返回一个待处理的 Promise),thunk 中的代码(从 Api 调度和拉取等)仍然会被执行吗?
谢谢
【问题讨论】:
-
它仍然会被执行,但它不再是异步的,因为你没有等待结果
标签: redux react-redux redux-thunk