gpt4 book ai didi

javascript - 为什么 'yield' 在 saga 中使用两次时会抛出错误?

转载 作者:行者123 更新时间:2023-12-02 23:56:49 25 4
gpt4 key购买 nike

我正在重新学习传奇,我想知道为什么我在 yield 上收到此错误向底部。我是否需要将这两行代码包装在另一个生成器函数中并调用它来减轻错误并构建它?

export default function* showPermissionWall() {
yield takeLatest(SHOW_TIMED_LOGIN_WALL, function* () {

setTimeout(() => {

yield put(showPermissionsNeededWall('Please log in', null)); // Parsing error: yield is a reserved word in strict mode
readTimeLoginBoxShown();

}, 1000 * SHOW_LOGIN_WALL_AFTER_IN_SECONDS); // Show after 3 minutes of reading
});

最佳答案

你的setTimeout中的回调函数不是生成器函数。因此,您不能在其中使用yield。

 setTimeout(function *() {

yield put(showPermissionsNeededWall('Please log in', null));
readTimeLoginBoxShown();

}, 1000 * SHOW_LOGIN_WALL_AFTER_IN_SECONDS);

应该可以帮助你

关于javascript - 为什么 'yield' 在 saga 中使用两次时会抛出错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55340958/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com