reactjs - 如果不将 return 放入 redux-thunk 中,这是否运作良好
问题描述
在我的项目中,我使用 redux-thunk 来处理异步函数。编写函数的常规方法如下,
return (dispatch) => {
return fetchAPI().then(doSomething)
}
但是我有一个问题,关于 fetchAPI 函数之前是否没有“返回”。这会对程序产生任何副作用吗?
return (dispatch) => {
fetchAPI().then(doSomething)
}
解决方案
当fetchAPI().then(doSomething)
返回一个Promise时,你可能想用它来检查它的状态,例如,如果你想在loading
某处指示一个状态。
如果您不使用该值,则不会引入任何副作用。
推荐阅读
- python-3.x - 从数据框中提取特定数据
- neo4j - Neo4j 密码中加权最短路径的关系约束
- angular - 如果 mat-select 保持“活动”状态且不可点击,如何以编程方式取消选择 mat-option
- unit-testing - 在 azuredevops 管道中发布代码覆盖率结果失败
- python - 如何从 jsonrpc 调用 tryton
- mysql - 使用 Docker 在工作站之间共享 MySQL 数据库
- javascript - 添加计数器
- python - 在这种情况下如何使用两个循环来迭代列表?
- python - 无法过滤 aws lambda 函数的 boto3 日志的日志流
- amazon-web-services - 如何对来自 AWS API Gateway 的测试版 HTTP Api 进行速率限制