首页 > 解决方案 > 如果不将 return 放入 redux-thunk 中,这是否运作良好

问题描述

在我的项目中,我使用 redux-thunk 来处理异步函数。编写函数的常规方法如下,

return (dispatch) => {
   return fetchAPI().then(doSomething)
}

但是我有一个问题,关于 fetchAPI 函数之前是否没有“返回”。这会对程序产生任何副作用吗?

return (dispatch) => {
  fetchAPI().then(doSomething)
}

标签: reactjsreact-reduxredux-thunk

解决方案


fetchAPI().then(doSomething)返回一个Promise时,你可能想用它来检查它的状态,例如,如果你想在loading某处指示一个状态。

如果您不使用该值,则不会引入任何副作用。


推荐阅读