redux - 为什么 yield call(response.json) 挂起?
问题描述
const response = yield call(fetch, `${config.backendUrl}/verify`, {
method: 'POST'
})
const responseJson = yield call(response.json)
console.log(responseJson)
这是来自 redux-saga 的代码。Yield 挂起并且console.log
不打印任何内容。但是,如果我用它替换response.json
它就() => response.json()
可以了。为什么?
解决方案
那是因为当您使用错误的上下文 ( ) 调用yield call(response.json)
时。response.json
this
您可以使用bind
(eg yield call(response.json.bind(response))
) 或指定context
(eg yield call([response, response.json])
) 来解决此问题,但call
这里真的没用。你可以:
const responseJson = yield response.json();
推荐阅读
- python - Altair 中的对数滑块
- r - RStudio 不会在新机器上渲染 Plotly 绘图
- python - 我如何从这个网站上抓取一个随机生成的句子
- python - Python 和 Scrapy - Scraper 不返回结果
- php - ServiceProvider 已注册但在控制器中不起作用
- c++ - 如何为基于范围的 for 重载 std::list 的取消引用运算符?
- google-cloud-platform - artman googleapis google Healthcare api 和 google 的 grpc fhir repo 无法生成客户端?
- excel - 下载带有主题的 Outlook 附件
- javascript - 填写用户名和姓氏并转到下一页
- javascript - 订阅返回未定义的变量