为什么 'yield' 在 saga 中使用两次时会抛出错误?
Why does 'yield' throw an error when used twice in saga?
我正在重新学习 sagas,我想知道为什么我在 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);
应该能帮到你
我正在重新学习 sagas,我想知道为什么我在 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);
应该能帮到你